Skip to content

Commit

Permalink
Inverse test
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed May 28, 2024
1 parent a5096cf commit 7c89a3e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/e2e/txn_write_data2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

0 comments on commit 7c89a3e

Please sign in to comment.