mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
add deploy script and test
This commit is contained in:
parent
29a7cf8f2b
commit
53e2f7cd46
2 changed files with 73 additions and 0 deletions
41
contracts/validator/validator.go
Normal file
41
contracts/validator/validator.go
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
package validator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Validator struct {
|
||||||
|
*contract.TomoValidatorSession
|
||||||
|
contractBackend bind.ContractBackend
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*Validator, error) {
|
||||||
|
validator, err := contract.NewTomoValidator(contractAddr, contractBackend)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Validator{
|
||||||
|
&contract.TomoValidatorSession{
|
||||||
|
Contract: validator,
|
||||||
|
TransactOpts: *transactOpts,
|
||||||
|
},
|
||||||
|
contractBackend,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *Validator, error) {
|
||||||
|
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return validatorAddr, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
validator, err := NewValidator(transactOpts, validatorAddr, contractBackend)
|
||||||
|
if err != nil {
|
||||||
|
return validatorAddr, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return validatorAddr, validator, nil
|
||||||
|
}
|
||||||
32
contracts/validator/validator_test.go
Normal file
32
contracts/validator/validator_test.go
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package validator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/big"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
|
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||||
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
|
addr = crypto.PubkeyToAddress(key.PublicKey)
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestENS(t *testing.T) {
|
||||||
|
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
||||||
|
transactOpts := bind.NewKeyedTransactor(key)
|
||||||
|
|
||||||
|
_, validator, err := DeployValidator(transactOpts, contractBackend)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("can't deploy root registry: %v", err)
|
||||||
|
}
|
||||||
|
contractBackend.Commit()
|
||||||
|
|
||||||
|
if _, err := validator.GetValidators(); err != nil {
|
||||||
|
t.Fatalf("can't get validators: %v", err)
|
||||||
|
}
|
||||||
|
contractBackend.Commit()
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue