mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
bugfix: unexpected pre node
This commit is contained in:
parent
77ac77cdb1
commit
dceb579b68
5 changed files with 63 additions and 7 deletions
|
|
@ -157,6 +157,19 @@ func (b *SimulatedBackend) StorageAt(ctx context.Context, contract common.Addres
|
|||
return val[:], nil
|
||||
}
|
||||
|
||||
// ForEachStorageAt returns func to read all keys, values in the storage
|
||||
func (b *SimulatedBackend) ForEachStorageAt(ctx context.Context, contract common.Address, blockNumber *big.Int, f func(key, val common.Hash) bool) error {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) != 0 {
|
||||
return errBlockNumberUnsupported
|
||||
}
|
||||
statedb, _ := b.blockchain.State()
|
||||
statedb.ForEachStorage(contract, f)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TransactionReceipt returns the receipt of a transaction.
|
||||
func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
|
||||
receipt, _, _, _ := core.GetReceipt(b.database, txHash)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package blocksigner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||
|
|
@ -25,7 +27,17 @@ package blocksigner
|
|||
}
|
||||
contractBackend.Commit()
|
||||
|
||||
signers, err := blockSigner.GetSigners(big.NewInt(0))
|
||||
d := time.Now().Add(1000 * time.Millisecond)
|
||||
ctx, _ := context.WithDeadline(context.Background(), d)
|
||||
code, _ := contractBackend.CodeAt(ctx, blockSignerAddress, nil)
|
||||
t.Log("contract code", common.ToHex(code))
|
||||
f := func(key, val common.Hash) bool {
|
||||
t.Log(key.Hex(), val.Hex())
|
||||
return true
|
||||
}
|
||||
contractBackend.ForEachStorageAt(ctx, blockSignerAddress, nil, f)
|
||||
|
||||
signers, err := blockSigner.GetSigners(big.NewInt(0))
|
||||
if err != nil {
|
||||
t.Fatalf("can't get candidates: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package randomize
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
|
@ -20,16 +23,27 @@ func TestRandomize(t *testing.T) {
|
|||
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
||||
transactOpts := bind.NewKeyedTransactor(key)
|
||||
|
||||
_, randomize, err := DeployRandomize(transactOpts, contractBackend)
|
||||
randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend)
|
||||
t.Log("contract address", randomizeAddress.String())
|
||||
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)
|
||||
code, _ := contractBackend.CodeAt(ctx, randomizeAddress, nil)
|
||||
t.Log("contract code", common.ToHex(code))
|
||||
f := func(key, val common.Hash) bool {
|
||||
t.Log(key.Hex(), val.Hex())
|
||||
return true
|
||||
}
|
||||
contractBackend.ForEachStorageAt(ctx, randomizeAddress, nil, f)
|
||||
|
||||
s, err := randomize.SetSecret(byte0)
|
||||
if err != nil {
|
||||
t.Fatalf("can't get secret: %v", err)
|
||||
}
|
||||
t.Log("secret", s)
|
||||
t.Log("tx data", s)
|
||||
contractBackend.Commit()
|
||||
}
|
||||
|
|
@ -28,7 +28,11 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address,
|
|||
}
|
||||
|
||||
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *Validator, error) {
|
||||
validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100))
|
||||
minDeposit := new(big.Int)
|
||||
|
||||
minDeposit.SetString("50000000000000000000000", 10)
|
||||
fmt.Println("--->", common.BigToHash(minDeposit).Hex())
|
||||
validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100))
|
||||
if err != nil {
|
||||
return validatorAddr, nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,20 @@
|
|||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"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/contracts"
|
||||
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -31,12 +34,22 @@ func TestValidator(t *testing.T) {
|
|||
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
||||
transactOpts := bind.NewKeyedTransactor(key)
|
||||
|
||||
_, validator, err := DeployValidator(transactOpts, contractBackend)
|
||||
validatorAddress, validator, err := DeployValidator(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)
|
||||
code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil)
|
||||
t.Log("contract code", common.ToHex(code))
|
||||
f := func(key, val common.Hash) bool {
|
||||
t.Log(key.Hex(), val.Hex())
|
||||
return true
|
||||
}
|
||||
contractBackend.ForEachStorageAt(ctx, validatorAddress, nil, f)
|
||||
|
||||
candidates, err := validator.GetCandidates()
|
||||
if err != nil {
|
||||
t.Fatalf("can't get candidates: %v", err)
|
||||
|
|
@ -61,7 +74,7 @@ func TestRewardBalance(t *testing.T) {
|
|||
accounts := []*bind.TransactOpts{acc1Opts, acc2Opts}
|
||||
transactOpts := bind.NewKeyedTransactor(acc1Key)
|
||||
|
||||
validatorAddr, _, baseValidator, err := contract.DeployXDCValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100))
|
||||
validatorAddr, _, baseValidator, err := contract.DeployXDCValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100), big.NewInt(100))
|
||||
if err != nil {
|
||||
t.Fatalf("can't deploy root registry: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue