github.com/evdatsion/aphelion-dpos-bft@v0.32.1/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 abci "github.com/evdatsion/aphelion-dpos-bft/abci/types" 9 ) 10 11 func TestABCIResults(t *testing.T) { 12 a := ABCIResult{Code: 0, Data: nil} 13 b := ABCIResult{Code: 0, Data: []byte{}} 14 c := ABCIResult{Code: 0, Data: []byte("one")} 15 d := ABCIResult{Code: 14, Data: nil} 16 e := ABCIResult{Code: 14, Data: []byte("foo")} 17 f := ABCIResult{Code: 14, Data: []byte("bar")} 18 19 // Nil and []byte{} should produce the same bytes 20 require.Equal(t, a.Bytes(), a.Bytes()) 21 require.Equal(t, b.Bytes(), b.Bytes()) 22 require.Equal(t, a.Bytes(), b.Bytes()) 23 24 // a and b should be the same, don't go in results. 25 results := ABCIResults{a, c, d, e, f} 26 27 // Make sure each result serializes differently 28 var last []byte 29 assert.Equal(t, last, a.Bytes()) // first one is empty 30 for i, res := range results[1:] { 31 bz := res.Bytes() 32 assert.NotEqual(t, last, bz, "%d", i) 33 last = bz 34 } 35 36 // Make sure that we can get a root hash from results and verify proofs. 37 root := results.Hash() 38 assert.NotEmpty(t, root) 39 40 for i, res := range results { 41 proof := results.ProveResult(i) 42 valid := proof.Verify(root, res.Bytes()) 43 assert.NoError(t, valid, "%d", i) 44 } 45 } 46 47 func TestABCIResultsBytes(t *testing.T) { 48 results := NewResults([]*abci.ResponseDeliverTx{ 49 {Code: 0, Data: []byte{}}, 50 {Code: 0, Data: []byte("one")}, 51 {Code: 14, Data: nil}, 52 {Code: 14, Data: []byte("foo")}, 53 {Code: 14, Data: []byte("bar")}, 54 }) 55 assert.NotNil(t, results.Bytes()) 56 }