From 61592d680ad4ed00b5e8e2a9a46c0c075922c3bc Mon Sep 17 00:00:00 2001 From: Steven LIU Date: Fri, 22 Nov 2024 17:37:35 +0800 Subject: [PATCH 1/6] finish update smoke test except TestRPCAPI --- test/config/test.erigon.rpc.config.yaml | 4 + test/e2e/smoke_test.go | 130 +++++++++++++++++++++--- 2 files changed, 119 insertions(+), 15 deletions(-) diff --git a/test/config/test.erigon.rpc.config.yaml b/test/config/test.erigon.rpc.config.yaml index 147e8a6680d..1c54b77a290 100644 --- a/test/config/test.erigon.rpc.config.yaml +++ b/test/config/test.erigon.rpc.config.yaml @@ -49,6 +49,10 @@ http.corsdomain: any http.timeouts.read: "10s" http.timeouts.write: "10s" http.timeouts.idle: "10s" +http.methodratelimit: "{\"methods\":[\"eth_syncing\"],\"count\":10,\"bucket\":1}" +http.apikeys: | + {"project":"project1","key":"","timeout":"2033-12-12","methods":["eth_syncing"],"count":100000,"bucket":1} + ws: true zkevm.apollo-enabled: false diff --git a/test/e2e/smoke_test.go b/test/e2e/smoke_test.go index c97887161bc..d5c1819b53d 100644 --- a/test/e2e/smoke_test.go +++ b/test/e2e/smoke_test.go @@ -15,10 +15,12 @@ import ( "github.com/ledgerwatch/erigon/core/types" "github.com/ledgerwatch/erigon/crypto" "github.com/ledgerwatch/erigon/ethclient" + "github.com/ledgerwatch/erigon/test/operations" "github.com/ledgerwatch/erigon/zkevm/encoding" "github.com/ledgerwatch/erigon/zkevm/etherman/smartcontracts/polygonzkevmbridge" "github.com/ledgerwatch/erigon/zkevm/log" + "github.com/stretchr/testify/require" ) @@ -70,6 +72,7 @@ func TestGetBatchSealTime(t *testing.T) { } func TestBridgeTx(t *testing.T) { + //done ctx := context.Background() l1Client, err := ethclient.Dial(operations.DefaultL1NetworkURL) require.NoError(t, err) @@ -77,13 +80,34 @@ func TestBridgeTx(t *testing.T) { require.NoError(t, err) transToken(t, ctx, l2Client, uint256.NewInt(encoding.Gwei), operations.DefaultL2AdminAddress) - amount := new(big.Int).SetUint64(10) + amount := new(big.Int).SetUint64(100) + //layer2 network id var destNetwork uint32 = 1 - destAddr := common.HexToAddress(operations.DefaultL1AdminAddress) + destAddr := common.HexToAddress(operations.DefaultL2AdminAddress) auth, err := operations.GetAuth(operations.DefaultL1AdminPrivateKey, operations.DefaultL1ChainID) require.NoError(t, err) + + wethAddress := common.HexToAddress("0x17a2a2e444a7f3446877d1b71eaa2b2ae7533baf") + wethToken, err := operations.NewToken(wethAddress, l2Client) + require.NoError(t, err) + + balanceBefore, err := wethToken.BalanceOf(&bind.CallOpts{}, destAddr) + require.NoError(t, err) + err = sendBridgeAsset(ctx, common.Address{}, amount, destNetwork, &destAddr, []byte{}, auth, common.HexToAddress(operations.BridgeAddr), l1Client) require.NoError(t, err) + + //wait for the bridge service + time.Sleep(30 * time.Second) + + balanceAfter, err := wethToken.BalanceOf(&bind.CallOpts{}, destAddr) + require.NoError(t, err) + require.Greater(t, balanceAfter.Uint64(), balanceBefore.Uint64()) +} +func Test2(t *testing.T) { + ctx := context.Background() + client, _ := ethclient.Dial(operations.DefaultL2NetworkURL) + transToken(t, ctx, client, uint256.NewInt(encoding.Gwei), blockAddress) } func TestClaimTx(t *testing.T) { @@ -126,11 +150,11 @@ func TestClaimTx(t *testing.T) { func TestNewAccFreeGas(t *testing.T) { ctx := context.Background() - client, err := ethclient.Dial(operations.DefaultL2NetworkURL) + client, _ := ethclient.Dial(operations.DefaultL2NetworkURL) transToken(t, ctx, client, uint256.NewInt(encoding.Gwei), operations.DefaultL2AdminAddress) var gas uint64 = 21000 - // newAcc transfer failed + //newAcc transfer failed from := common.HexToAddress(operations.DefaultL2NewAcc1Address) to := common.HexToAddress(operations.DefaultL2AdminAddress) nonce, err := client.PendingNonceAt(ctx, from) @@ -151,8 +175,10 @@ func TestNewAccFreeGas(t *testing.T) { require.NoError(t, err) err = client.SendTransaction(ctx, signedTx) require.Error(t, err) + require.True(t, strings.Contains(err.Error(), "RPC error response: FEE_TOO_LOW: underpriced"), "Expected error message not found") err = operations.WaitTxToBeMined(ctx, client, signedTx, 5) require.Error(t, err) + require.True(t, strings.Contains(err.Error(), "context deadline exceeded"), "Expected error message not found") // seq -> newAcc from = common.HexToAddress(operations.DefaultL2AdminAddress) @@ -200,27 +226,45 @@ func TestNewAccFreeGas(t *testing.T) { err = operations.WaitTxToBeMined(ctx, client, signedTx, operations.DefaultTimeoutTxToBeMined) require.NoError(t, err) } - func TestWhiteAndBlockList(t *testing.T) { if testing.Short() { t.Skip() } ctx := context.Background() client, err := ethclient.Dial(operations.DefaultL2NetworkURL) + require.NoError(t, err) + from := common.HexToAddress(operations.DefaultL2AdminAddress) - to := common.HexToAddress(blockAddress) + blockAddressConverted := common.HexToAddress(blockAddress) + nonBlockAddress := common.HexToAddress(operations.DefaultL2NewAcc1Address) + nonce, err := client.PendingNonceAt(ctx, from) + require.NoError(t, err) + gasPrice, err := client.SuggestGasPrice(ctx) + require.NoError(t, err) + gas, err := client.EstimateGas(ctx, ethereum.CallMsg{ From: from, - To: &to, + To: &blockAddressConverted, Value: uint256.NewInt(10), }) require.NoError(t, err) - var tx types.Transaction = &types.LegacyTx{ + + var txToBlockAddress types.Transaction = &types.LegacyTx{ CommonTx: types.CommonTx{ Nonce: nonce, - To: &to, + To: &blockAddressConverted, + Gas: gas, + Value: uint256.NewInt(10), + }, + GasPrice: uint256.MustFromBig(gasPrice), + } + + var txToNonBlockAddress types.Transaction = &types.LegacyTx{ + CommonTx: types.CommonTx{ + Nonce: nonce, + To: &nonBlockAddress, Gas: gas, Value: uint256.NewInt(10), }, @@ -231,18 +275,29 @@ func TestWhiteAndBlockList(t *testing.T) { require.NoError(t, err) signer := types.MakeSigner(operations.GetTestChainConfig(operations.DefaultL2ChainID), 1, 0) - signedTx, err := types.SignTx(tx, *signer, privateKey) + + signedTxToBlockAddress, err := types.SignTx(txToBlockAddress, *signer, privateKey) require.NoError(t, err) - err = client.SendTransaction(ctx, signedTx) + err = client.SendTransaction(ctx, signedTxToBlockAddress) log.Infof("err:%v", err) require.True(t, strings.Contains(err.Error(), "INTERNAL_ERROR: blocked receiver")) + + signedTxToNonBlockAddress, err := types.SignTx(txToNonBlockAddress, *signer, privateKey) + require.NoError(t, err) + + err = client.SendTransaction(ctx, signedTxToNonBlockAddress) + require.NoError(t, err) + + //TODO: sender in blocklist should fail + //now only admin account have balance. So we may add another account that has balance. } func TestRPCAPI(t *testing.T) { if testing.Short() { t.Skip() } + var err error for i := 0; i < 1000; i++ { _, err1 := operations.GetEthSyncing(operations.DefaultL2NetworkURL) @@ -253,10 +308,10 @@ func TestRPCAPI(t *testing.T) { } require.True(t, strings.Contains(err.Error(), "rate limit exceeded")) - //for i := 0; i < 1000; i++ { - // _, err1 := operations.GetEthSyncing(operations.DefaultL2NetworkURL + "/apikey1") - // require.NoError(t, err1) - //} + for i := 0; i < 1000; i++ { + _, err1 := operations.GetEthSyncing(operations.DefaultL2NetworkURL + "/45543e0adc5dd3e316044909d32501a5") + require.NoError(t, err1) + } } func TestChainID(t *testing.T) { @@ -402,6 +457,8 @@ func transToken(t *testing.T, ctx context.Context, client *ethclient.Client, amo Value: amount, }) require.NoError(t, err) + log.Infof("gas: %d", gas) + log.Infof("gasPrice: %d", gasPrice) var tx types.Transaction = &types.LegacyTx{ CommonTx: types.CommonTx{ @@ -521,3 +578,46 @@ func sendBridgeAsset( const txTimeout = 60 * time.Second return operations.WaitTxToBeMined(ctx, c, tx, txTimeout) } +func getWETHBalance(client *ethclient.Client, owner common.Address) (*big.Int, error) { + const wethAddress = "0x17a2a2e444a7f3446877d1b71eaa2b2ae7533baf" + wethAddr := common.HexToAddress(wethAddress) + + // ERC20 代币的 balanceOf(address) 方法签名 + callData := append([]byte{0x70, 0xa0, 0x82, 0x31}, owner.Bytes()...) + + // 使用带超时的上下文 + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + result, err := client.CallContract(ctx, ethereum.CallMsg{ + To: &wethAddr, + Data: callData, + }, nil) + if err != nil { + log.Infof("Error calling contract: %v", err) + return nil, err + } + + if len(result) < 32 { + err := fmt.Errorf("result too short") + log.Infof("Error: %v", err) + return nil, err + } + + // 解析返回值 + balance := new(big.Int).SetBytes(result[:32]) + return balance, nil +} + +// 测试getWETHBalance函数 +func TestGetWETHBalance(t *testing.T) { + client, err := ethclient.Dial(operations.DefaultL2NetworkURL) + require.NoError(t, err) + balance, err := getWETHBalance(client, common.HexToAddress(operations.DefaultL2AdminAddress)) + require.NoError(t, err) + log.Infof("WETH balance: %v", balance) +} + +func Test1(t *testing.T) { + log.Infof("这是一条测试日志") +} From 9f6cfaf1e267fa62c255c3f2c19a3761ed6c92ef Mon Sep 17 00:00:00 2001 From: Steven LIU Date: Thu, 5 Dec 2024 15:35:58 +0800 Subject: [PATCH 2/6] update TestRPCAPI --- test/config/test.erigon.rpc.config.yaml | 2 +- test/e2e/smoke_test.go | 65 ++++++++++++++++--------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/test/config/test.erigon.rpc.config.yaml b/test/config/test.erigon.rpc.config.yaml index 1c54b77a290..c7f1fa4c16b 100644 --- a/test/config/test.erigon.rpc.config.yaml +++ b/test/config/test.erigon.rpc.config.yaml @@ -51,7 +51,7 @@ http.timeouts.write: "10s" http.timeouts.idle: "10s" http.methodratelimit: "{\"methods\":[\"eth_syncing\"],\"count\":10,\"bucket\":1}" http.apikeys: | - {"project":"project1","key":"","timeout":"2033-12-12","methods":["eth_syncing"],"count":100000,"bucket":1} + {"project":"Biconomy","key":"45543e0adc5dd3e316044909d32501a5","timeout":"2030-12-31","methods":["eth_syncing"],"count":10000,"bucket":1} ws: true diff --git a/test/e2e/smoke_test.go b/test/e2e/smoke_test.go index d5c1819b53d..83e9e4eb371 100644 --- a/test/e2e/smoke_test.go +++ b/test/e2e/smoke_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/big" + "os" "strings" "testing" "time" @@ -15,6 +16,7 @@ import ( "github.com/ledgerwatch/erigon/core/types" "github.com/ledgerwatch/erigon/crypto" "github.com/ledgerwatch/erigon/ethclient" + "gopkg.in/yaml.v2" "github.com/ledgerwatch/erigon/test/operations" "github.com/ledgerwatch/erigon/zkevm/encoding" @@ -104,11 +106,6 @@ func TestBridgeTx(t *testing.T) { require.NoError(t, err) require.Greater(t, balanceAfter.Uint64(), balanceBefore.Uint64()) } -func Test2(t *testing.T) { - ctx := context.Background() - client, _ := ethclient.Dial(operations.DefaultL2NetworkURL) - transToken(t, ctx, client, uint256.NewInt(encoding.Gwei), blockAddress) -} func TestClaimTx(t *testing.T) { ctx := context.Background() @@ -298,19 +295,29 @@ func TestRPCAPI(t *testing.T) { t.Skip() } - var err error - for i := 0; i < 1000; i++ { - _, err1 := operations.GetEthSyncing(operations.DefaultL2NetworkURL) - if err1 != nil { - err = err1 - break - } - } - require.True(t, strings.Contains(err.Error(), "rate limit exceeded")) + config, err := LoadConfig("../../test/config/test.erigon.rpc.config.yaml") + require.NoError(t, err) + + if config.HTTPAPIKeys != "" { - for i := 0; i < 1000; i++ { - _, err1 := operations.GetEthSyncing(operations.DefaultL2NetworkURL + "/45543e0adc5dd3e316044909d32501a5") - require.NoError(t, err1) + _, err := operations.GetEthSyncing(operations.DefaultL2NetworkURL) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), "no authentication")) + + _, err = operations.GetEthSyncing(operations.DefaultL2NetworkURL + "/45543e0adc5dd3e316044909d32501a5") + require.NoError(t, err) + } else { + + var rateErr error + for i := 0; i < 1000; i++ { + _, err1 := operations.GetEthSyncing(operations.DefaultL2NetworkURL) + if err1 != nil { + rateErr = err1 + break + } + } + t.Logf("Actual error message: %s", rateErr.Error()) + require.True(t, strings.Contains(rateErr.Error(), "rate limit exceeded")) } } @@ -582,10 +589,8 @@ func getWETHBalance(client *ethclient.Client, owner common.Address) (*big.Int, e const wethAddress = "0x17a2a2e444a7f3446877d1b71eaa2b2ae7533baf" wethAddr := common.HexToAddress(wethAddress) - // ERC20 代币的 balanceOf(address) 方法签名 callData := append([]byte{0x70, 0xa0, 0x82, 0x31}, owner.Bytes()...) - // 使用带超时的上下文 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -604,12 +609,10 @@ func getWETHBalance(client *ethclient.Client, owner common.Address) (*big.Int, e return nil, err } - // 解析返回值 balance := new(big.Int).SetBytes(result[:32]) return balance, nil } -// 测试getWETHBalance函数 func TestGetWETHBalance(t *testing.T) { client, err := ethclient.Dial(operations.DefaultL2NetworkURL) require.NoError(t, err) @@ -618,6 +621,22 @@ func TestGetWETHBalance(t *testing.T) { log.Infof("WETH balance: %v", balance) } -func Test1(t *testing.T) { - log.Infof("这是一条测试日志") +type Config struct { + HTTPMethodRateLimit string `yaml:"http.methodratelimit"` + HTTPAPIKeys string `yaml:"http.apikeys"` +} + +func LoadConfig(path string) (*Config, error) { + data, err := os.ReadFile(path) + if err != nil { + return nil, err + } + + var config Config + err = yaml.Unmarshal(data, &config) + if err != nil { + return nil, err + } + + return &config, nil } From 96b890e81b1830fc44f184da74c245cfb5c67e18 Mon Sep 17 00:00:00 2001 From: Steven LIU Date: Fri, 6 Dec 2024 10:45:29 +0800 Subject: [PATCH 3/6] remove getWETHBalance --- test/config/test.erigon.rpc.config.yaml | 4 +-- test/e2e/smoke_test.go | 38 +------------------------ 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/test/config/test.erigon.rpc.config.yaml b/test/config/test.erigon.rpc.config.yaml index c7f1fa4c16b..c048c9df46a 100644 --- a/test/config/test.erigon.rpc.config.yaml +++ b/test/config/test.erigon.rpc.config.yaml @@ -50,8 +50,8 @@ http.timeouts.read: "10s" http.timeouts.write: "10s" http.timeouts.idle: "10s" http.methodratelimit: "{\"methods\":[\"eth_syncing\"],\"count\":10,\"bucket\":1}" -http.apikeys: | - {"project":"Biconomy","key":"45543e0adc5dd3e316044909d32501a5","timeout":"2030-12-31","methods":["eth_syncing"],"count":10000,"bucket":1} +# http.apikeys: | +# {"project":"Biconomy","key":"45543e0adc5dd3e316044909d32501a5","timeout":"2030-12-31","methods":["eth_syncing"],"count":10000,"bucket":1} ws: true diff --git a/test/e2e/smoke_test.go b/test/e2e/smoke_test.go index 83e9e4eb371..f0aa0365479 100644 --- a/test/e2e/smoke_test.go +++ b/test/e2e/smoke_test.go @@ -74,7 +74,6 @@ func TestGetBatchSealTime(t *testing.T) { } func TestBridgeTx(t *testing.T) { - //done ctx := context.Background() l1Client, err := ethclient.Dial(operations.DefaultL1NetworkURL) require.NoError(t, err) @@ -316,7 +315,7 @@ func TestRPCAPI(t *testing.T) { break } } - t.Logf("Actual error message: %s", rateErr.Error()) + require.True(t, strings.Contains(rateErr.Error(), "rate limit exceeded")) } } @@ -585,41 +584,6 @@ func sendBridgeAsset( const txTimeout = 60 * time.Second return operations.WaitTxToBeMined(ctx, c, tx, txTimeout) } -func getWETHBalance(client *ethclient.Client, owner common.Address) (*big.Int, error) { - const wethAddress = "0x17a2a2e444a7f3446877d1b71eaa2b2ae7533baf" - wethAddr := common.HexToAddress(wethAddress) - - callData := append([]byte{0x70, 0xa0, 0x82, 0x31}, owner.Bytes()...) - - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - result, err := client.CallContract(ctx, ethereum.CallMsg{ - To: &wethAddr, - Data: callData, - }, nil) - if err != nil { - log.Infof("Error calling contract: %v", err) - return nil, err - } - - if len(result) < 32 { - err := fmt.Errorf("result too short") - log.Infof("Error: %v", err) - return nil, err - } - - balance := new(big.Int).SetBytes(result[:32]) - return balance, nil -} - -func TestGetWETHBalance(t *testing.T) { - client, err := ethclient.Dial(operations.DefaultL2NetworkURL) - require.NoError(t, err) - balance, err := getWETHBalance(client, common.HexToAddress(operations.DefaultL2AdminAddress)) - require.NoError(t, err) - log.Infof("WETH balance: %v", balance) -} type Config struct { HTTPMethodRateLimit string `yaml:"http.methodratelimit"` From cd4125144eac007cc221bccd0c344f3de42424a5 Mon Sep 17 00:00:00 2001 From: Steven LIU Date: Wed, 11 Dec 2024 11:14:54 +0800 Subject: [PATCH 4/6] update TextBridgeTx --- test/e2e/smoke_test.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/test/e2e/smoke_test.go b/test/e2e/smoke_test.go index f0aa0365479..351e7b2cbac 100644 --- a/test/e2e/smoke_test.go +++ b/test/e2e/smoke_test.go @@ -98,12 +98,25 @@ func TestBridgeTx(t *testing.T) { err = sendBridgeAsset(ctx, common.Address{}, amount, destNetwork, &destAddr, []byte{}, auth, common.HexToAddress(operations.BridgeAddr), l1Client) require.NoError(t, err) - //wait for the bridge service - time.Sleep(30 * time.Second) + const maxAttempts = 20 - balanceAfter, err := wethToken.BalanceOf(&bind.CallOpts{}, destAddr) - require.NoError(t, err) - require.Greater(t, balanceAfter.Uint64(), balanceBefore.Uint64()) + var balanceAfter *big.Int + for i := 0; i < maxAttempts; i++ { + time.Sleep(1 * time.Second) + + balanceAfter, err = wethToken.BalanceOf(&bind.CallOpts{}, destAddr) + require.NoError(t, err) + + if balanceAfter.Cmp(balanceBefore) > 0 { + return + } + } + + t.Errorf("bridge transaction failed after %d seconds: balance did not increase (before: %s, after: %s)", + maxAttempts, + balanceBefore.String(), + balanceAfter.String(), + ) } func TestClaimTx(t *testing.T) { From 6956c0c090eabd7ec69c2a8a69334ba9ed3f539e Mon Sep 17 00:00:00 2001 From: Steven LIU Date: Wed, 11 Dec 2024 11:36:09 +0800 Subject: [PATCH 5/6] update TestBridgeTx --- test/e2e/smoke_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/smoke_test.go b/test/e2e/smoke_test.go index 351e7b2cbac..d27e4f0ff2d 100644 --- a/test/e2e/smoke_test.go +++ b/test/e2e/smoke_test.go @@ -98,7 +98,7 @@ func TestBridgeTx(t *testing.T) { err = sendBridgeAsset(ctx, common.Address{}, amount, destNetwork, &destAddr, []byte{}, auth, common.HexToAddress(operations.BridgeAddr), l1Client) require.NoError(t, err) - const maxAttempts = 20 + const maxAttempts = 120 var balanceAfter *big.Int for i := 0; i < maxAttempts; i++ { From 0f487e290a74e798ae8e334f10f21cb54335296f Mon Sep 17 00:00:00 2001 From: Steven LIU Date: Wed, 11 Dec 2024 12:10:51 +0800 Subject: [PATCH 6/6] update makefile --- test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Makefile b/test/Makefile index 276f8ef648c..100dd0fd526 100644 --- a/test/Makefile +++ b/test/Makefile @@ -125,7 +125,7 @@ test: test-1 ## Runs all e2e tests sleep 3 .PHONY: test-1 -test-1: stop run ## Runs group 1 e2e tests checking race conditions +test-1: stop all ## Runs group 1 e2e tests checking race conditions sleep 3 docker ps -a trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -failfast -race -v -p 1 -timeout 600s ../ci/e2e-1/...