github.com/opzlabs/tendermint@v0.34.27-terra.rc.2/types/results_test.go (about) 1 package types 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 9 abci "github.com/tendermint/tendermint/abci/types" 10 ) 11 12 func TestABCIResults(t *testing.T) { 13 a := &abci.ResponseDeliverTx{Code: 0, Data: nil} 14 b := &abci.ResponseDeliverTx{Code: 0, Data: []byte{}} 15 c := &abci.ResponseDeliverTx{Code: 0, Data: []byte("one")} 16 d := &abci.ResponseDeliverTx{Code: 14, Data: nil} 17 e := &abci.ResponseDeliverTx{Code: 14, Data: []byte("foo")} 18 f := &abci.ResponseDeliverTx{Code: 14, Data: []byte("bar")} 19 20 // Nil and []byte{} should produce the same bytes 21 bzA, err := a.Marshal() 22 require.NoError(t, err) 23 bzB, err := b.Marshal() 24 require.NoError(t, err) 25 26 require.Equal(t, bzA, bzB) 27 28 // a and b should be the same, don't go in results. 29 results := ABCIResults{a, c, d, e, f} 30 31 // Make sure each result serializes differently 32 last := []byte{} 33 assert.Equal(t, last, bzA) // first one is empty 34 for i, res := range results[1:] { 35 bz, err := res.Marshal() 36 require.NoError(t, err) 37 38 assert.NotEqual(t, last, bz, "%d", i) 39 last = bz 40 } 41 42 // Make sure that we can get a root hash from results and verify proofs. 43 root := results.Hash() 44 assert.NotEmpty(t, root) 45 46 for i, res := range results { 47 bz, err := res.Marshal() 48 require.NoError(t, err) 49 50 proof := results.ProveResult(i) 51 valid := proof.Verify(root, bz) 52 assert.NoError(t, valid, "%d", i) 53 } 54 }