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

Commit c099b49

Browse files
committed
fix(test): fix workflow errors
1 parent bbe9ed7 commit c099b49

File tree

3 files changed

+92
-88
lines changed

3 files changed

+92
-88
lines changed

internal/testutils/helper.go

-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"time"
1313

1414
"github.com/cenkalti/backoff/v4"
15-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1615
"github.com/ethereum/go-ethereum/common"
1716
"github.com/ethereum/go-ethereum/common/hexutil"
1817
"github.com/ethereum/go-ethereum/core/types"
@@ -156,20 +155,6 @@ func ProposeAndInsertValidBlock(
156155
return event
157156
}
158157

159-
func DepositEtherToL2(s *ClientTestSuite, depositerPrivKey *ecdsa.PrivateKey, recipient common.Address) {
160-
config, err := s.RPCClient.TaikoL1.GetConfig(nil)
161-
s.Nil(err)
162-
163-
opts, err := bind.NewKeyedTransactorWithChainID(depositerPrivKey, s.RPCClient.L1ChainID)
164-
s.Nil(err)
165-
opts.Value = config.EthDepositMinAmount
166-
167-
for i := 0; i < int(config.EthDepositMinCountPerBlock); i++ {
168-
_, err = s.RPCClient.TaikoL1.DepositEtherToL2(opts, recipient)
169-
s.Nil(err)
170-
}
171-
}
172-
173158
// NewTestProverServer starts a new prover server that has channel listeners to respond and react
174159
// to requests for capacity, which provers can call.
175160
func NewTestProverServer(

internal/testutils/suite.go

+29-23
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,41 @@ func (s *ClientTestSuite) SetupTest() {
9696
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
9797
s.Nil(err)
9898

99-
decimal, err := rpcCli.TaikoToken.Decimals(nil)
100-
s.Nil(err)
101-
10299
// Increase allowance for AssignmentHook and TaikoL1
103-
opts, err = bind.NewKeyedTransactorWithChainID(l1ProverPrivKey, rpcCli.L1ChainID)
104-
s.Nil(err)
105-
106-
bigInt := new(big.Int).Exp(big.NewInt(1_000_000_000), new(big.Int).SetUint64(uint64(decimal)), nil)
107-
_, err = rpcCli.TaikoToken.Approve(
108-
opts,
109-
common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
110-
bigInt,
111-
)
112-
s.Nil(err)
113-
114-
_, err = rpcCli.TaikoToken.Approve(
115-
opts,
116-
common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
117-
bigInt,
118-
)
119-
s.Nil(err)
120-
121-
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
122-
s.Nil(err)
100+
s.setAllowance(l1ProverPrivKey)
101+
s.setAllowance(ownerPrivKey)
123102
}
124103
s.Nil(rpcCli.L1.CallContext(context.Background(), &s.testnetL1SnapshotID, "evm_snapshot"))
125104
s.NotEmpty(s.testnetL1SnapshotID)
126105
}
127106

107+
func (s *ClientTestSuite) setAllowance(key *ecdsa.PrivateKey) {
108+
decimal, err := s.RPCClient.TaikoToken.Decimals(nil)
109+
s.Nil(err)
110+
111+
bigInt := new(big.Int).Exp(big.NewInt(1_000_000_000), new(big.Int).SetUint64(uint64(decimal)), nil)
112+
113+
opts, err := bind.NewKeyedTransactorWithChainID(key, s.RPCClient.L1ChainID)
114+
s.Nil(err)
115+
116+
_, err = s.RPCClient.TaikoToken.Approve(
117+
opts,
118+
common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
119+
bigInt,
120+
)
121+
s.Nil(err)
122+
123+
tx, err := s.RPCClient.TaikoToken.Approve(
124+
opts,
125+
common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
126+
bigInt,
127+
)
128+
s.Nil(err)
129+
130+
_, err = rpc.WaitReceipt(context.Background(), s.RPCClient.L1, tx)
131+
s.Nil(err)
132+
}
133+
128134
func (s *ClientTestSuite) setAddress(ownerPrivKey *ecdsa.PrivateKey, name [32]byte, address common.Address) {
129135
var (
130136
salt = RandomHash()

prover/prover_test.go

+63-50
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package prover
22

33
import (
44
"context"
5+
"crypto/ecdsa"
56
"math/big"
67
"net/url"
78
"os"
@@ -42,57 +43,8 @@ func (s *ProverTestSuite) SetupTest() {
4243
l1ProverPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROVER_PRIVATE_KEY")))
4344
s.Nil(err)
4445

45-
proverServerURL := testutils.LocalRandomProverEndpoint()
46-
port, err := strconv.Atoi(proverServerURL.Port())
47-
s.Nil(err)
48-
49-
decimal, err := s.RPCClient.TaikoToken.Decimals(nil)
50-
s.Nil(err)
51-
52-
allowance := new(big.Int).Exp(big.NewInt(1_000_000_100), new(big.Int).SetUint64(uint64(decimal)), nil)
53-
5446
ctx, cancel := context.WithCancel(context.Background())
55-
p := new(Prover)
56-
s.Nil(InitFromConfig(ctx, p, &Config{
57-
L1WsEndpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
58-
L1HttpEndpoint: os.Getenv("L1_NODE_HTTP_ENDPOINT"),
59-
L2WsEndpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
60-
L2HttpEndpoint: os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT"),
61-
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
62-
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
63-
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
64-
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
65-
GuardianProverAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")),
66-
L1ProverPrivKey: l1ProverPrivKey,
67-
Dummy: true,
68-
ProveUnassignedBlocks: true,
69-
Capacity: 1024,
70-
MinOptimisticTierFee: common.Big1,
71-
MinSgxTierFee: common.Big1,
72-
MinPseZkevmTierFee: common.Big1,
73-
MinSgxAndPseZkevmTierFee: common.Big1,
74-
HTTPServerPort: uint64(port),
75-
WaitReceiptTimeout: 12 * time.Second,
76-
DatabasePath: "",
77-
Allowance: allowance,
78-
RPCTimeout: 3 * time.Second,
79-
BackOffMaxRetrys: 3,
80-
}))
81-
p.srv = testutils.NewTestProverServer(
82-
&s.ClientTestSuite,
83-
l1ProverPrivKey,
84-
proverServerURL,
85-
)
86-
87-
p.guardianProverSender = guardianproversender.New(
88-
p.cfg.L1ProverPrivKey,
89-
p.cfg.GuardianProverHealthCheckServerEndpoint,
90-
memorydb.New(),
91-
p.rpc,
92-
p.proverAddress,
93-
)
94-
95-
s.p = p
47+
proverServerURL := s.initProver(ctx, l1ProverPrivKey)
9648
s.cancel = cancel
9749

9850
// Init driver
@@ -280,6 +232,12 @@ func (s *ProverTestSuite) TestContestWrongBlocks() {
280232
close(contestedSink)
281233
}()
282234

235+
contesterKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_CONTRACT_OWNER_PRIVATE_KEY")))
236+
s.Nil(err)
237+
238+
s.NotNil(s.initProver(context.Background(), contesterKey))
239+
s.p.cfg.ContesterMode = true
240+
283241
s.Greater(header.Number.Uint64(), uint64(0))
284242
s.Nil(s.p.onTransitionProved(context.Background(), event))
285243

@@ -496,3 +454,58 @@ func (s *ProverTestSuite) TestSetApprovalAlreadySetHigher() {
496454
func TestProverTestSuite(t *testing.T) {
497455
suite.Run(t, new(ProverTestSuite))
498456
}
457+
458+
func (s *ProverTestSuite) initProver(ctx context.Context, key *ecdsa.PrivateKey) *url.URL {
459+
proverServerURL := testutils.LocalRandomProverEndpoint()
460+
port, err := strconv.Atoi(proverServerURL.Port())
461+
s.Nil(err)
462+
463+
decimal, err := s.RPCClient.TaikoToken.Decimals(nil)
464+
s.Nil(err)
465+
466+
allowance := new(big.Int).Exp(big.NewInt(1_000_000_100), new(big.Int).SetUint64(uint64(decimal)), nil)
467+
468+
p := new(Prover)
469+
s.Nil(InitFromConfig(ctx, p, &Config{
470+
L1WsEndpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
471+
L1HttpEndpoint: os.Getenv("L1_NODE_HTTP_ENDPOINT"),
472+
L2WsEndpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
473+
L2HttpEndpoint: os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT"),
474+
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
475+
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
476+
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
477+
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
478+
GuardianProverAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")),
479+
L1ProverPrivKey: key,
480+
Dummy: true,
481+
ProveUnassignedBlocks: true,
482+
Capacity: 1024,
483+
MinOptimisticTierFee: common.Big1,
484+
MinSgxTierFee: common.Big1,
485+
MinPseZkevmTierFee: common.Big1,
486+
MinSgxAndPseZkevmTierFee: common.Big1,
487+
HTTPServerPort: uint64(port),
488+
WaitReceiptTimeout: 12 * time.Second,
489+
DatabasePath: "",
490+
Allowance: allowance,
491+
RPCTimeout: 3 * time.Second,
492+
BackOffMaxRetrys: 3,
493+
}))
494+
p.srv = testutils.NewTestProverServer(
495+
&s.ClientTestSuite,
496+
key,
497+
proverServerURL,
498+
)
499+
500+
p.guardianProverSender = guardianproversender.New(
501+
key,
502+
p.cfg.GuardianProverHealthCheckServerEndpoint,
503+
memorydb.New(),
504+
p.rpc,
505+
p.proverAddress,
506+
)
507+
508+
s.p = p
509+
510+
return proverServerURL
511+
}

0 commit comments

Comments
 (0)