Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into fix/golangci-lint_1
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp authored Jan 23, 2024
2 parents 9808160 + 60f128b commit e8c3f4c
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 88 deletions.
15 changes: 0 additions & 15 deletions internal/testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/cenkalti/backoff/v4"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -156,20 +155,6 @@ func ProposeAndInsertValidBlock(
return event
}

func DepositEtherToL2(s *ClientTestSuite, depositerPrivKey *ecdsa.PrivateKey, recipient common.Address) {
config, err := s.RPCClient.TaikoL1.GetConfig(nil)
s.Nil(err)

opts, err := bind.NewKeyedTransactorWithChainID(depositerPrivKey, s.RPCClient.L1ChainID)
s.Nil(err)
opts.Value = config.EthDepositMinAmount

for i := 0; i < int(config.EthDepositMinCountPerBlock); i++ {
_, err = s.RPCClient.TaikoL1.DepositEtherToL2(opts, recipient)
s.Nil(err)
}
}

// NewTestProverServer starts a new prover server that has channel listeners to respond and react
// to requests for capacity, which provers can call.
func NewTestProverServer(
Expand Down
52 changes: 29 additions & 23 deletions internal/testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,41 @@ func (s *ClientTestSuite) SetupTest() {
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
s.Nil(err)

decimal, err := rpcCli.TaikoToken.Decimals(nil)
s.Nil(err)

// Increase allowance for AssignmentHook and TaikoL1
opts, err = bind.NewKeyedTransactorWithChainID(l1ProverPrivKey, rpcCli.L1ChainID)
s.Nil(err)

bigInt := new(big.Int).Exp(big.NewInt(1_000_000_000), new(big.Int).SetUint64(uint64(decimal)), nil)
_, err = rpcCli.TaikoToken.Approve(
opts,
common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
bigInt,
)
s.Nil(err)

_, err = rpcCli.TaikoToken.Approve(
opts,
common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
bigInt,
)
s.Nil(err)

_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
s.Nil(err)
s.setAllowance(l1ProverPrivKey)
s.setAllowance(ownerPrivKey)
}
s.Nil(rpcCli.L1.CallContext(context.Background(), &s.testnetL1SnapshotID, "evm_snapshot"))
s.NotEmpty(s.testnetL1SnapshotID)
}

func (s *ClientTestSuite) setAllowance(key *ecdsa.PrivateKey) {
decimal, err := s.RPCClient.TaikoToken.Decimals(nil)
s.Nil(err)

bigInt := new(big.Int).Exp(big.NewInt(1_000_000_000), new(big.Int).SetUint64(uint64(decimal)), nil)

opts, err := bind.NewKeyedTransactorWithChainID(key, s.RPCClient.L1ChainID)
s.Nil(err)

_, err = s.RPCClient.TaikoToken.Approve(
opts,
common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
bigInt,
)
s.Nil(err)

tx, err := s.RPCClient.TaikoToken.Approve(
opts,
common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
bigInt,
)
s.Nil(err)

_, err = rpc.WaitReceipt(context.Background(), s.RPCClient.L1, tx)
s.Nil(err)
}

func (s *ClientTestSuite) setAddress(ownerPrivKey *ecdsa.PrivateKey, name [32]byte, address common.Address) {
var (
salt = RandomHash()
Expand Down
122 changes: 72 additions & 50 deletions prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package prover

import (
"context"
"crypto/ecdsa"
"math/big"
"net/url"
"os"
Expand Down Expand Up @@ -42,57 +43,8 @@ func (s *ProverTestSuite) SetupTest() {
l1ProverPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROVER_PRIVATE_KEY")))
s.Nil(err)

proverServerURL := testutils.LocalRandomProverEndpoint()
port, err := strconv.Atoi(proverServerURL.Port())
s.Nil(err)

decimal, err := s.RPCClient.TaikoToken.Decimals(nil)
s.Nil(err)

allowance := new(big.Int).Exp(big.NewInt(1_000_000_100), new(big.Int).SetUint64(uint64(decimal)), nil)

ctx, cancel := context.WithCancel(context.Background())
p := new(Prover)
s.Nil(InitFromConfig(ctx, p, &Config{
L1WsEndpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L1HttpEndpoint: os.Getenv("L1_NODE_HTTP_ENDPOINT"),
L2WsEndpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
L2HttpEndpoint: os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
GuardianProverAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")),
L1ProverPrivKey: l1ProverPrivKey,
Dummy: true,
ProveUnassignedBlocks: true,
Capacity: 1024,
MinOptimisticTierFee: common.Big1,
MinSgxTierFee: common.Big1,
MinPseZkevmTierFee: common.Big1,
MinSgxAndPseZkevmTierFee: common.Big1,
HTTPServerPort: uint64(port),
WaitReceiptTimeout: 12 * time.Second,
DatabasePath: "",
Allowance: allowance,
RPCTimeout: 3 * time.Second,
BackOffMaxRetrys: 3,
}))
p.srv = testutils.NewTestProverServer(
&s.ClientTestSuite,
l1ProverPrivKey,
proverServerURL,
)

p.guardianProverSender = guardianproversender.New(
p.cfg.L1ProverPrivKey,
p.cfg.GuardianProverHealthCheckServerEndpoint,
memorydb.New(),
p.rpc,
p.proverAddress,
)

s.p = p
proverServerURL := s.initProver(ctx, l1ProverPrivKey)
s.cancel = cancel

// Init driver
Expand Down Expand Up @@ -280,6 +232,21 @@ func (s *ProverTestSuite) TestContestWrongBlocks() {
s.NotEqual(header.Hash(), common.BytesToHash(event.Tran.BlockHash[:]))
s.Equal(header.ParentHash, common.BytesToHash(event.Tran.ParentHash[:]))

// Contest the transition.
contestedSink := make(chan *bindings.TaikoL1ClientTransitionContested)

Check failure on line 236 in prover/prover_test.go

View workflow job for this annotation

GitHub Actions / Lint

no new variables on left side of :=
contestedSub, err := s.p.rpc.TaikoL1.WatchTransitionContested(nil, contestedSink, nil)

Check failure on line 237 in prover/prover_test.go

View workflow job for this annotation

GitHub Actions / Lint

no new variables on left side of := (typecheck)
s.Nil(err)
defer func() {
contestedSub.Unsubscribe()
close(contestedSink)
}()

contesterKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_CONTRACT_OWNER_PRIVATE_KEY")))
s.Nil(err)

s.NotNil(s.initProver(context.Background(), contesterKey))
s.p.cfg.ContesterMode = true

s.Greater(header.Number.Uint64(), uint64(0))
s.Nil(s.p.onTransitionProved(context.Background(), event))

Expand Down Expand Up @@ -496,3 +463,58 @@ func (s *ProverTestSuite) TestSetApprovalAlreadySetHigher() {
func TestProverTestSuite(t *testing.T) {
suite.Run(t, new(ProverTestSuite))
}

func (s *ProverTestSuite) initProver(ctx context.Context, key *ecdsa.PrivateKey) *url.URL {
proverServerURL := testutils.LocalRandomProverEndpoint()
port, err := strconv.Atoi(proverServerURL.Port())
s.Nil(err)

decimal, err := s.RPCClient.TaikoToken.Decimals(nil)
s.Nil(err)

allowance := new(big.Int).Exp(big.NewInt(1_000_000_100), new(big.Int).SetUint64(uint64(decimal)), nil)

p := new(Prover)
s.Nil(InitFromConfig(ctx, p, &Config{
L1WsEndpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L1HttpEndpoint: os.Getenv("L1_NODE_HTTP_ENDPOINT"),
L2WsEndpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
L2HttpEndpoint: os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
GuardianProverAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")),
L1ProverPrivKey: key,
Dummy: true,
ProveUnassignedBlocks: true,
Capacity: 1024,
MinOptimisticTierFee: common.Big1,
MinSgxTierFee: common.Big1,
MinPseZkevmTierFee: common.Big1,
MinSgxAndPseZkevmTierFee: common.Big1,
HTTPServerPort: uint64(port),
WaitReceiptTimeout: 12 * time.Second,
DatabasePath: "",
Allowance: allowance,
RPCTimeout: 3 * time.Second,
BackOffMaxRetrys: 3,
}))
p.srv = testutils.NewTestProverServer(
&s.ClientTestSuite,
key,
proverServerURL,
)

p.guardianProverSender = guardianproversender.New(
key,
p.cfg.GuardianProverHealthCheckServerEndpoint,
memorydb.New(),
p.rpc,
p.proverAddress,
)

s.p = p

return proverServerURL
}

0 comments on commit e8c3f4c

Please sign in to comment.