Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2130 from bandprotocol/rolling-seed-test
Browse files Browse the repository at this point in the history
chain/test: Add ABCI begin block rolling seed test
  • Loading branch information
sorawit authored Jul 2, 2020
2 parents d055141 + c408d7a commit ecbd33c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Chain

- (chore) [\#2130](https://github.com/bandprotocol/bandchain/pull/2130) Add ABCI begin block rolling seed test.
- (bug) [\#2075](https://github.com/bandprotocol/bandchain/pull/2075) Add height check when sync on db and fix external id can be zero.
- (bug) [\#2125](https://github.com/bandprotocol/bandchain/pull/2125) Fix request with duplicate external id and empty raw request bug.
- (chore) [\#2126](https://github.com/bandprotocol/bandchain/pull/2126) More test cleanups in request and result keepers.
Expand Down
38 changes: 38 additions & 0 deletions chain/x/oracle/abci_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package oracle_test

import (
"encoding/hex"
"testing"

"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/bandprotocol/bandchain/chain/x/oracle/testapp"
)

func fromHex(hexStr string) []byte {
res, err := hex.DecodeString(hexStr)
if err != nil {
panic(err)
}
return res
}

func TestRollingSeedCorrect(t *testing.T) {
app, ctx, k := testapp.CreateTestInput()
// Initially rolling seed should be all zeros.
require.Equal(t, fromHex("0000000000000000000000000000000000000000000000000000000000000000"), k.GetRollingSeed(ctx))
// Every begin block, the rolling seed should get updated.
app.BeginBlocker(ctx, abci.RequestBeginBlock{
Hash: fromHex("0100000000000000000000000000000000000000000000000000000000000000"),
})
require.Equal(t, fromHex("0000000000000000000000000000000000000000000000000000000000000001"), k.GetRollingSeed(ctx))
app.BeginBlocker(ctx, abci.RequestBeginBlock{
Hash: fromHex("0200000000000000000000000000000000000000000000000000000000000000"),
})
require.Equal(t, fromHex("0000000000000000000000000000000000000000000000000000000000000102"), k.GetRollingSeed(ctx))
app.BeginBlocker(ctx, abci.RequestBeginBlock{
Hash: fromHex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
})
require.Equal(t, fromHex("00000000000000000000000000000000000000000000000000000000000102ff"), k.GetRollingSeed(ctx))
}

0 comments on commit ecbd33c

Please sign in to comment.