fix unit test, safe cancel context

This commit is contained in:
Nguyen Sy Thanh Son 2018-07-16 06:44:51 +00:00
parent dd353d6bb5
commit 66b1e8ad50
4 changed files with 11 additions and 6 deletions

View file

@ -173,12 +173,13 @@ func (w *wizard) makeGenesis() {
validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend)
if err != nil {
fmt.Println("can't deploy root registry: %v", err)
fmt.Println("Can't deploy root registry")
}
contractBackend.Commit()
d := time.Now().Add(1000 * time.Millisecond)
ctx, _ := context.WithDeadline(context.Background(), d)
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil)
storage := make(map[common.Hash]common.Hash)
f := func(key, val common.Hash) bool {

View file

@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
)
@ -21,14 +22,15 @@ func TestBlockSigner(t *testing.T) {
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
transactOpts := bind.NewKeyedTransactor(key)
_, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend)
blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend)
if err != nil {
t.Fatalf("can't deploy root registry: %v", err)
}
contractBackend.Commit()
d := time.Now().Add(1000 * time.Millisecond)
ctx, _ := context.WithDeadline(context.Background(), d)
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, blockSignerAddress, nil)
t.Log("contract code", common.ToHex(code))
f := func(key, val common.Hash) bool {

View file

@ -31,7 +31,8 @@ func TestRandomize(t *testing.T) {
contractBackend.Commit()
d := time.Now().Add(1000 * time.Millisecond)
ctx, _ := context.WithDeadline(context.Background(), d)
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, randomizeAddress, nil)
t.Log("contract code", common.ToHex(code))
f := func(key, val common.Hash) bool {

View file

@ -40,7 +40,8 @@ func TestValidator(t *testing.T) {
contractBackend.Commit()
d := time.Now().Add(1000 * time.Millisecond)
ctx, _ := context.WithDeadline(context.Background(), d)
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil)
t.Log("contract code", common.ToHex(code))
f := func(key, val common.Hash) bool {