From 7c89a3e916949b4cc63d283d046a4e1753f71969 Mon Sep 17 00:00:00 2001 From: Ethan Reesor Date: Tue, 28 May 2024 11:00:34 -0500 Subject: [PATCH] Inverse test --- test/e2e/txn_write_data2_test.go | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/e2e/txn_write_data2_test.go b/test/e2e/txn_write_data2_test.go index 95405d900..d26c70cde 100644 --- a/test/e2e/txn_write_data2_test.go +++ b/test/e2e/txn_write_data2_test.go @@ -354,3 +354,48 @@ func TestWriteDataScratch(t *testing.T) { require.NotEqual(t, st.TxID.String(), r.Value.ID.String()) } } + +func TestWriteDataMain(t *testing.T) { + alice := build. + Identity("alice").Create("book"). + Data("data").Create().Identity(). + Book("book").Page(1).Create().AddCredits(1e9).Book().Identity() + aliceKey := alice.Book("book").Page(1). + GenerateKey(SignatureTypeED25519) + + // Initialize + g := new(core.GlobalValues) + g.ExecutorVersion = ExecutorVersionLatest + sim := NewSim(t, + simulator.SimpleNetwork(t.Name(), 1, 1), + simulator.Genesis(GenesisTime).With(alice), + ) + + st := sim.BuildAndSubmitTxnSuccessfully( + build.Transaction().For(alice, "data"). + WriteData().DoubleHash("foo"). + SignWith(alice, "book", "1").Version(1).Timestamp(1).PrivateKey(aliceKey)) + require.NoError(t, st.AsError()) + sim.StepUntil( + Txn(st.TxID).Succeeds()) + + // The transaction is on the main chain + r := sim.QueryMainChainEntries(alice.Url().JoinPath("data"), &api.ChainQuery{Name: "main", Range: &api.RangeOptions{ + Start: 0, + Count: api.Ptr[uint64](1), + FromEnd: true, + Expand: api.Ptr(true), + }}) + require.Len(t, r.Records, 1) + require.Equal(t, st.TxID.String(), r.Records[0].Value.ID.String()) + require.IsType(t, (*WriteData)(nil), r.Records[0].Value.Message.Transaction.Body) + + // Not the scratch chain + r = sim.QueryMainChainEntries(alice.Url().JoinPath("data"), &api.ChainQuery{Name: "scratch", Range: &api.RangeOptions{ + Start: 0, + Expand: api.Ptr(true), + }}) + for _, r := range r.Records { + require.NotEqual(t, st.TxID.String(), r.Value.ID.String()) + } +}