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

Commit

Permalink
test: add setAddress method
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Nov 29, 2023
1 parent 5f42412 commit 2e31257
Show file tree
Hide file tree
Showing 8 changed files with 3,387 additions and 91 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5aea2950247332f10270994a24eca7e51bc0e427
b20ff337693efc3191a00ff883d258de322fdf3c
3,247 changes: 3,247 additions & 0 deletions bindings/gen_taiko_timelock_controller.go

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions driver/chain_syncer/chain_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,7 @@ func (s *ChainSyncerTestSuite) TestAheadOfProtocolVerifiedHead2() {
log.Info("LatestVerifiedBlock number", "number", s.s.state.GetLatestVerifiedBlock().ID.Uint64())

// increase evm time to make blocks verifiable.
var result uint64
s.Nil(s.RpcClient.L1RawRPC.CallContext(
context.Background(),
&result,
"evm_increaseTime",
(1024 * time.Hour).Seconds(),
))
s.NotNil(result)
log.Info("EVM time increase", "number", result)
s.IncreaseTime(uint64((1024 * time.Hour).Seconds()))

// interact with TaikoL1 contract to allow for verification of L2 blocks
tx, err := s.s.rpc.TaikoL1.VerifyBlocks(opts, uint64(3))
Expand Down
4 changes: 4 additions & 0 deletions integration_test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TAIKO_TOKEN_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.taiko_token' | sed '
ADDRESS_MANAGER_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.address_manager_for_rollup' | sed 's/\"//g')
GUARDIAN_PROVER_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.guardian_prover' | sed 's/\"//g')
ASSIGNMENT_HOOK_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.assignment_hook' | sed 's/\"//g')
TIMELOCK_CONTROLLER=$(echo $DEPLOYMENT_JSON | jq '.timelock_controller' | sed 's/\"//g')

trap "docker compose -f $TESTNET_CONFIG down -v" EXIT INT KILL ERR

Expand All @@ -41,6 +42,7 @@ echo "TAIKO_TOKEN_CONTRACT_ADDRESS: $TAIKO_TOKEN_CONTRACT_ADDRESS"
echo "L1_SIGNAL_SERVICE_CONTRACT_ADDRESS: $L1_SIGNAL_SERVICE_CONTRACT_ADDRESS"
echo "GUARDIAN_PROVER_CONTRACT_ADDRESS: $GUARDIAN_PROVER_CONTRACT_ADDRESS"
echo "ASSIGNMENT_HOOK_CONTRACT_ADDRESS: $ASSIGNMENT_HOOK_CONTRACT_ADDRESS"
echo "TIMELOCK_CONTROLLER: $TIMELOCK_CONTROLLER"

if [ "$RUN_TESTS" == "true" ]; then
L1_NODE_HTTP_ENDPOINT=http://localhost:18545 \
Expand All @@ -52,10 +54,12 @@ if [ "$RUN_TESTS" == "true" ]; then
TAIKO_L2_ADDRESS=0x1670010000000000000000000000000000010001 \
TAIKO_TOKEN_ADDRESS=$TAIKO_TOKEN_CONTRACT_ADDRESS \
ASSIGNMENT_HOOK_ADDRESS=$ASSIGNMENT_HOOK_CONTRACT_ADDRESS \
TIMELOCK_CONTROLLER=$TIMELOCK_CONTROLLER \
ADDRESS_MANAGER_CONTRACT_ADDRESS=$ADDRESS_MANAGER_CONTRACT_ADDRESS \
GUARDIAN_PROVER_CONTRACT_ADDRESS=$GUARDIAN_PROVER_CONTRACT_ADDRESS \
L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$L1_SIGNAL_SERVICE_CONTRACT_ADDRESS \
L1_CONTRACT_OWNER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
L1_SECURITY_COUNCIL_PRIVATE_KEY=dbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97 \
L1_PROPOSER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
L2_SUGGESTED_FEE_RECIPIENT=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
L1_PROVER_PRIVATE_KEY=59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d \
Expand Down
100 changes: 50 additions & 50 deletions integration_test/nodes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,53 @@ services:
- --host
- "0.0.0.0"

# l2_execution_engine:
# image: gcr.io/evmchain/taiko-geth:taiko
# restart: unless-stopped
# pull_policy: always
# volumes:
# - .:/host
# ports:
# - 28545:8545
# - 28546:8546
# - 28551:8551
# command:
# - --nodiscover
# - --gcmode
# - archive
# - --syncmode
# - full
# - --datadir
# - /data/taiko-geth
# - --networkid
# - "167001"
# - --metrics
# - --metrics.expensive
# - --metrics.addr
# - "0.0.0.0"
# - --http
# - --http.addr
# - "0.0.0.0"
# - --http.vhosts
# - "*"
# - --http.corsdomain
# - "*"
# - --ws
# - --ws.addr
# - "0.0.0.0"
# - --ws.origins
# - "*"
# - --authrpc.addr
# - "0.0.0.0"
# - --authrpc.port
# - "8551"
# - --authrpc.vhosts
# - "*"
# - --authrpc.jwtsecret
# - /host/jwt.hex
# - --allow-insecure-unlock
# - --http.api
# - admin,debug,eth,net,web3,txpool,miner,taiko
# - --ws.api
# - admin,debug,eth,net,web3,txpool,miner,taiko
# - --taiko
l2_execution_engine:
image: gcr.io/evmchain/taiko-geth:taiko
restart: unless-stopped
pull_policy: always
volumes:
- .:/host
ports:
- 28545:8545
- 28546:8546
- 28551:8551
command:
- --nodiscover
- --gcmode
- archive
- --syncmode
- full
- --datadir
- /data/taiko-geth
- --networkid
- "167001"
- --metrics
- --metrics.expensive
- --metrics.addr
- "0.0.0.0"
- --http
- --http.addr
- "0.0.0.0"
- --http.vhosts
- "*"
- --http.corsdomain
- "*"
- --ws
- --ws.addr
- "0.0.0.0"
- --ws.origins
- "*"
- --authrpc.addr
- "0.0.0.0"
- --authrpc.port
- "8551"
- --authrpc.vhosts
- "*"
- --authrpc.jwtsecret
- /host/jwt.hex
- --allow-insecure-unlock
- --http.api
- admin,debug,eth,net,web3,txpool,miner,taiko
- --ws.api
- admin,debug,eth,net,web3,txpool,miner,taiko
- --taiko
2 changes: 1 addition & 1 deletion integration_test/nodes/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cd $TAIKO_MONO_DIR/packages/protocol &&
OWNER=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC \
TAIKO_L2_ADDRESS=0x1670010000000000000000000000000000010001 \
L2_SIGNAL_SERVICE=0x1670010000000000000000000000000000010005 \
SECURITY_COUNCIL=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
SECURITY_COUNCIL=0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f \
SHARED_ADDRESS_MANAGER=0x0000000000000000000000000000000000000000 \
PROPOSER=0x0000000000000000000000000000000000000000 \
PROPOSER_ONE=0x0000000000000000000000000000000000000000 \
Expand Down
4 changes: 4 additions & 0 deletions scripts/gen_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ cat ${TAIKO_MONO_DIR}/packages/protocol/out/AssignmentHook.sol/AssignmentHook.js
jq .abi |
${ABIGEN_BIN} --abi - --type AssignmentHook --pkg bindings --out $DIR/../bindings/gen_assignment_hook.go

cat ${TAIKO_MONO_DIR}/packages/protocol/out/TaikoTimelockController.sol/TaikoTimelockController.json |
jq .abi |
${ABIGEN_BIN} --abi - --type TaikoTimelockController --pkg bindings --out $DIR/../bindings/gen_taiko_timelock_controller.go

git -C ${TAIKO_MONO_DIR} log --format="%H" -n 1 >./bindings/.githead

echo "🍻 Go contract bindings generated!"
109 changes: 79 additions & 30 deletions testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"net/url"
"os"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -88,49 +89,24 @@ func (s *ClientTestSuite) SetupTest() {

if allowance.Cmp(common.Big0) == 0 {
// Do not verify zk && sgx proofs in tests.
addressManager, err := bindings.NewAddressManager(
common.HexToAddress(os.Getenv("ADDRESS_MANAGER_CONTRACT_ADDRESS")),
rpcCli.L1,
)
s.Nil(err)

chainID, err := rpcCli.L1.ChainID(context.Background())
securityConcilPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(os.Getenv("L1_SECURITY_COUNCIL_PRIVATE_KEY")))
s.Nil(err)
s.setAddress(securityConcilPrivKey, rpc.StringToBytes32("tier_sgx_and_pse_zkevm"), common.Address{})
s.setAddress(securityConcilPrivKey, rpc.StringToBytes32("tier_sgx"), common.Address{})

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

opts, err := bind.NewKeyedTransactorWithChainID(ownerPrivKey, rpcCli.L1ChainID)
s.Nil(err)

tx, err := addressManager.SetAddress(
opts,
chainID.Uint64(),
rpc.StringToBytes32("tier_sgx_and_pse_zkevm"),
common.Address{},
)
s.Nil(err)
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
s.Nil(err)

tx, err = addressManager.SetAddress(opts, chainID.Uint64(), rpc.StringToBytes32("tier_sgx"), common.Address{})
s.Nil(err)
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
s.Nil(err)

// Transfer some tokens to provers.
balance, err := rpcCli.TaikoToken.BalanceOf(nil, crypto.PubkeyToAddress(ownerPrivKey.PublicKey))
s.Nil(err)
s.Greater(balance.Cmp(common.Big0), 0)

opts, err = bind.NewKeyedTransactorWithChainID(ownerPrivKey, rpcCli.L1ChainID)
opts, err := bind.NewKeyedTransactorWithChainID(ownerPrivKey, rpcCli.L1ChainID)
s.Nil(err)
proverBalance := new(big.Int).Div(balance, common.Big2)
if proverBalance.Cmp(common.Big0) == 1 {
tx, err = rpcCli.TaikoToken.Transfer(
opts,
crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), proverBalance,
)
tx, err := rpcCli.TaikoToken.Transfer(opts, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), proverBalance)
s.Nil(err)
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
s.Nil(err)
Expand Down Expand Up @@ -162,6 +138,73 @@ func (s *ClientTestSuite) SetupTest() {
s.NotEmpty(s.testnetL1SnapshotID)
}

func (s *ClientTestSuite) setAddress(ownerPrivKey *ecdsa.PrivateKey, name [32]byte, address common.Address) {
var (
salt = RandomHash()
sevenDays = uint64((7 * 24 * time.Hour).Seconds())
)

controller, err := bindings.NewTaikoTimelockController(
common.HexToAddress(os.Getenv("TIMELOCK_CONTROLLER")),
s.RpcClient.L1,
)
s.Nil(err)

opts, err := bind.NewKeyedTransactorWithChainID(ownerPrivKey, s.RpcClient.L1ChainID)
s.Nil(err)

proposerRole, err := controller.PROPOSERROLE(nil)
s.Nil(err)

executorRole, err := controller.EXECUTORROLE(nil)
s.Nil(err)

tx, err := controller.GrantRole(opts, proposerRole, crypto.PubkeyToAddress(ownerPrivKey.PublicKey))
s.Nil(err)
_, err = rpc.WaitReceipt(context.Background(), s.RpcClient.L1, tx)
s.Nil(err)

tx, err = controller.GrantRole(opts, executorRole, crypto.PubkeyToAddress(ownerPrivKey.PublicKey))
s.Nil(err)
_, err = rpc.WaitReceipt(context.Background(), s.RpcClient.L1, tx)
s.Nil(err)

addressManagerABI, err := bindings.AddressManagerMetaData.GetAbi()
s.Nil(err)

data, err := addressManagerABI.Pack("setAddress", s.RpcClient.L1ChainID.Uint64(), name, address)
s.Nil(err)

tx, err = controller.Schedule(
opts,
common.HexToAddress(os.Getenv("ADDRESS_MANAGER_CONTRACT_ADDRESS")),
common.Big0,
data,
[32]byte{},
salt,
new(big.Int).SetUint64(sevenDays),
)
s.Nil(err)

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

s.IncreaseTime(2 * sevenDays)

tx, err = controller.Execute(
opts,
common.HexToAddress(os.Getenv("ADDRESS_MANAGER_CONTRACT_ADDRESS")),
common.Big0,
data,
[32]byte{},
salt,
)
s.Nil(err)

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

func (s *ClientTestSuite) TearDownTest() {
var revertRes bool
s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), &revertRes, "evm_revert", s.testnetL1SnapshotID))
Expand All @@ -174,3 +217,9 @@ func (s *ClientTestSuite) TearDownTest() {
func (s *ClientTestSuite) SetL1Automine(automine bool) {
s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), nil, "evm_setAutomine", automine))
}

func (s *ClientTestSuite) IncreaseTime(time uint64) {
var result uint64
s.RpcClient.L1RawRPC.CallContext(context.Background(), &result, "evm_increaseTime", time)

Check failure on line 223 in testutils/suite.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `s.RpcClient.L1RawRPC.CallContext` is not checked (errcheck)
s.NotZero(result)
}

0 comments on commit 2e31257

Please sign in to comment.