Browse Source

check-in finalize block hash tests

wb/txrset
William Banfield 3 years ago
parent
commit
c34adb7235
No known key found for this signature in database GPG Key ID: EFAD3442BF29E3AC
1 changed files with 41 additions and 0 deletions
  1. +41
    -0
      abci/types/types_test.go

+ 41
- 0
abci/types/types_test.go View File

@ -0,0 +1,41 @@
package types_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
)
func TestHashAndProveResults(t *testing.T) {
trs := []*abci.ExecTxResult{
{Code: 0, Data: nil},
{Code: 0, Data: []byte{}},
{Code: 0, Data: []byte("one")},
{Code: 14, Data: nil},
{Code: 14, Data: []byte("foo")},
{Code: 14, Data: []byte("bar")},
}
// Nil and []byte{} should produce the same bytes
bz0, err := trs[0].Marshal()
require.NoError(t, err)
bz1, err := trs[1].Marshal()
require.NoError(t, err)
require.Equal(t, bz0, bz1)
// Make sure that we can get a root hash from results and verify proofs.
root := abci.MustHashResults(trs)
assert.NotEmpty(t, root)
for i, tr := range trs {
bz, err := tr.Marshal()
require.NoError(t, err)
proof := abci.MustProveResult(trs, i)
valid := proof.Verify(root, bz)
assert.NoError(t, valid, "%d", i)
}
}

Loading…
Cancel
Save