mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
50 lines
No EOL
1.4 KiB
Go
50 lines
No EOL
1.4 KiB
Go
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"
|
|
)
|
|
|
|
var (
|
|
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
addr = crypto.PubkeyToAddress(key.PublicKey)
|
|
byte0 = make([][32]byte, 2)
|
|
)
|
|
|
|
func TestRandomize(t *testing.T) {
|
|
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
|
transactOpts := bind.NewKeyedTransactor(key)
|
|
|
|
randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend, big.NewInt(2))
|
|
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, 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 {
|
|
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("tx data", s)
|
|
contractBackend.Commit()
|
|
} |