Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for most used admin transactions #2473

Merged
merged 18 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
* [2549](https://github.com/zeta-chain/node/pull/2459) - add separate accounts for each policy in e2e tests
* [2415](https://github.com/zeta-chain/node/pull/2415) - add e2e test for upgrade and test admin functionalities
* [2440](https://github.com/zeta-chain/node/pull/2440) - Add e2e test for TSS migration

* [2473](https://github.com/zeta-chain/node/pull/2473) - add e2e tests for most used admin transactions

### Fixes

Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestUpdateBytecodeZRC20Name,
e2etests.TestUpdateBytecodeConnectorName,
e2etests.TestDepositEtherLiquidityCapName,
e2etests.TestCriticalAdminTransactionsName,

// TestMigrateChainSupportName tests EVM chain migration. Currently this test doesn't work with Anvil because pre-EIP1559 txs are not supported
// See issue below for details
Expand Down
1 change: 1 addition & 0 deletions docs/cli/zetacored/zetacored_query_crosschain.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ zetacored query crosschain [flags]
* [zetacored query crosschain show-cctx](zetacored_query_crosschain_show-cctx.md) - shows a CCTX
* [zetacored query crosschain show-gas-price](zetacored_query_crosschain_show-gas-price.md) - shows a gasPrice
* [zetacored query crosschain show-inbound-hash-to-cctx](zetacored_query_crosschain_show-inbound-hash-to-cctx.md) - shows a inboundHashToCctx
* [zetacored query crosschain show-inbound-tracker](zetacored_query_crosschain_show-inbound-tracker.md) - shows an inbound tracker by chainID and txHash
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
* [zetacored query crosschain show-outbound-tracker](zetacored_query_crosschain_show-outbound-tracker.md) - shows an outbound tracker
* [zetacored query crosschain show-rate-limiter-flags](zetacored_query_crosschain_show-rate-limiter-flags.md) - shows the rate limiter flags

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# query crosschain show-inbound-tracker

shows an inbound tracker by chainID and txHash

```
zetacored query crosschain show-inbound-tracker [chainID] [txHash] [flags]
```

### Options

```
--grpc-addr string the gRPC endpoint to use for this chain
--grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS
--height int Use a specific height to query state at (this can error if the node is pruning state)
-h, --help help for show-inbound-tracker
--node string [host]:[port] to Tendermint RPC interface for this chain
-o, --output string Output format (text|json)
```

### Options inherited from parent commands

```
--chain-id string The network chain ID
--home string directory for config and data
--log_format string The logging format (json|plain)
--log_level string The logging level (trace|debug|info|warn|error|fatal|panic)
--log_no_color Disable colored logs
--trace print out full stack trace on errors
```

### SEE ALSO

* [zetacored query crosschain](zetacored_query_crosschain.md) - Querying commands for the crosschain module

kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28846,6 +28846,30 @@ paths:
type: string
tags:
- Query
/zeta-chain/crosschain/inboundTracker/{chain_id}/{tx_hash}:
get:
operationId: Query_InboundTracker
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/crosschainQueryInboundTrackerResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: chain_id
in: path
required: true
type: string
format: int64
- name: tx_hash
in: path
required: true
type: string
tags:
- Query
/zeta-chain/crosschain/inboundTrackerByChain/{chain_id}:
get:
operationId: Query_InboundTrackerAllByChain
Expand Down Expand Up @@ -57397,6 +57421,11 @@ definitions:
items:
type: object
$ref: '#/definitions/crosschainCrossChainTx'
crosschainQueryInboundTrackerResponse:
type: object
properties:
inbound_tracker:
$ref: '#/definitions/crosschainInboundTracker'
crosschainQueryLastZetaHeightResponse:
type: object
properties:
Expand Down
19 changes: 13 additions & 6 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ const (
Admin tests
Test admin functionalities
*/
TestDepositEtherLiquidityCapName = "deposit_eth_liquidity_cap"
TestMigrateChainSupportName = "migrate_chain_support"
TestPauseZRC20Name = "pause_zrc20"
TestUpdateBytecodeZRC20Name = "update_bytecode_zrc20"
TestUpdateBytecodeConnectorName = "update_bytecode_connector"
TestRateLimiterName = "rate_limiter"
TestDepositEtherLiquidityCapName = "deposit_eth_liquidity_cap"
TestMigrateChainSupportName = "migrate_chain_support"
TestPauseZRC20Name = "pause_zrc20"
TestUpdateBytecodeZRC20Name = "update_bytecode_zrc20"
TestUpdateBytecodeConnectorName = "update_bytecode_connector"
TestRateLimiterName = "rate_limiter"
TestCriticalAdminTransactionsName = "critical_admin_transactions"

TestMigrateTSSName = "migrate_TSS"

Expand Down Expand Up @@ -533,6 +534,12 @@ var AllE2ETests = []runner.E2ETest{
[]runner.ArgDefinition{},
TestRateLimiter,
),
runner.NewE2ETest(
TestCriticalAdminTransactionsName,
"test critical admin transactions",
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
[]runner.ArgDefinition{},
TestCriticalAdminTransactions,
),
/*
Special tests
*/
Expand Down
105 changes: 105 additions & 0 deletions e2e/e2etests/test_admin_transactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package e2etests

import (
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
"github.com/zeta-chain/zetacore/testutil/sample"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

// TestCriticalAdminTransactions tests critical admin transactions that are the most used on mainnet .
// The complete list is
// MsgUpdateChainParams
// MsgRefundAbortedCCTX
// MsgEnableCCTX
// MsgDisableCCTX
// MsgUpdateGasPriceIncreaseFlags
// MsgAddInboundTracker
// MsgUpdateZRC20LiquidityCap
// MsgDeploySystemContracts
// MsgWhitelistERC20
// MsgPauseZRC20
// MsgMigrateTssFunds
// MsgUpdateTssAddress
//
// However, the transactions other than `AddToInboundTracker` and `UpdateGasPriceIncreaseFlags` have already been used in other tests.
func TestCriticalAdminTransactions(r *runner.E2ERunner, _ []string) {
TestAddToInboundTracker(r)
TestUpdateGasPriceIncreaseFlags(r)

Check warning on line 33 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L31-L33

Added lines #L31 - L33 were not covered by tests
}

func TestUpdateGasPriceIncreaseFlags(r *runner.E2ERunner) {

Check warning on line 36 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L36

Added line #L36 was not covered by tests
// Set default flags on zetacore
defaultFlags := observertypes.DefaultGasPriceIncreaseFlags
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
msgGasPriceFlags := observertypes.NewMsgUpdateGasPriceIncreaseFlags(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName),
defaultFlags,
)
_, err := r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msgGasPriceFlags)
require.NoError(r, err)

Check warning on line 44 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L38-L44

Added lines #L38 - L44 were not covered by tests

// create a new set of flag values by incrementing the epoch length by 1
defaultFlagsUpdated := defaultFlags
defaultFlagsUpdated.EpochLength = defaultFlags.EpochLength + 1

Check warning on line 48 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L47-L48

Added lines #L47 - L48 were not covered by tests

// Update the flags on zetacore with the new values
msgGasPriceFlags = observertypes.NewMsgUpdateGasPriceIncreaseFlags(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName),
defaultFlagsUpdated,
)
_, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msgGasPriceFlags)
require.NoError(r, err)

Check warning on line 56 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L51-L56

Added lines #L51 - L56 were not covered by tests

r.WaitForBlocks(1)

Check warning on line 58 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L58

Added line #L58 was not covered by tests

// Verify that the flags have been updated
flags, err := r.ObserverClient.CrosschainFlags(r.Ctx, &observertypes.QueryGetCrosschainFlagsRequest{})
require.NoError(r, err)
require.Equal(r, defaultFlagsUpdated.EpochLength, flags.CrosschainFlags.GasPriceIncreaseFlags.EpochLength)

Check warning on line 63 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L61-L63

Added lines #L61 - L63 were not covered by tests
}

func TestAddToInboundTracker(r *runner.E2ERunner) {
chainEth := chains.GoerliLocalnet
chainBtc := chains.BitcoinRegtest
msgEth := crosschaintypes.NewMsgAddInboundTracker(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.EmergencyPolicyName),
chainEth.ChainId,
coin.CoinType_Gas,
sample.Hash().Hex(),
)
_, err := r.ZetaTxServer.BroadcastTx(utils.EmergencyPolicyName, msgEth)
require.NoError(r, err)

Check warning on line 76 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L66-L76

Added lines #L66 - L76 were not covered by tests

msgBtc := crosschaintypes.NewMsgAddInboundTracker(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.EmergencyPolicyName),
chainBtc.ChainId,
coin.CoinType_Gas,
sample.BtcHash().String(),
)

Check warning on line 83 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L78-L83

Added lines #L78 - L83 were not covered by tests

_, err = r.ZetaTxServer.BroadcastTx(utils.EmergencyPolicyName, msgBtc)
require.NoError(r, err)

Check warning on line 86 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L85-L86

Added lines #L85 - L86 were not covered by tests

r.WaitForBlocks(1)

Check warning on line 88 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L88

Added line #L88 was not covered by tests

tracker, err := r.CctxClient.InboundTracker(r.Ctx, &crosschaintypes.QueryInboundTrackerRequest{
ChainId: msgEth.ChainId,
TxHash: msgEth.TxHash,
})
require.NoError(r, err)
require.NotNil(r, tracker)
require.Equal(r, msgEth.TxHash, tracker.InboundTracker.TxHash)

Check warning on line 96 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L90-L96

Added lines #L90 - L96 were not covered by tests

tracker, err = r.CctxClient.InboundTracker(r.Ctx, &crosschaintypes.QueryInboundTrackerRequest{
ChainId: msgBtc.ChainId,
TxHash: msgBtc.TxHash,
})
require.NoError(r, err)
require.NotNil(r, tracker)
require.Equal(r, msgBtc.TxHash, tracker.InboundTracker.TxHash)

Check warning on line 104 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L98-L104

Added lines #L98 - L104 were not covered by tests
}
29 changes: 29 additions & 0 deletions e2e/runner/zeta.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
package runner

import (
"fmt"
"math/big"
"time"

"github.com/cenkalti/backoff/v4"
ethcommon "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
zetaconnectoreth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.eth.sol"
connectorzevm "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zetaconnectorzevm.sol"

"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/pkg/retry"
"github.com/zeta-chain/zetacore/x/crosschain/types"
)

func (r *E2ERunner) WaitForBlocks(n int64) {
height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{})
if err != nil {
return

Check warning on line 23 in e2e/runner/zeta.go

View check run for this annotation

Codecov / codecov/patch

e2e/runner/zeta.go#L20-L23

Added lines #L20 - L23 were not covered by tests
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}
call := func() error {
return retry.Retry(r.waitForBlock(height.Height + n))

Check warning on line 26 in e2e/runner/zeta.go

View check run for this annotation

Codecov / codecov/patch

e2e/runner/zeta.go#L25-L26

Added lines #L25 - L26 were not covered by tests
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}

bo := backoff.NewConstantBackOff(time.Second * 5)
boWithMaxRetries := backoff.WithMaxRetries(bo, 10)
err = retry.DoWithBackoff(call, boWithMaxRetries)
require.NoError(r, err, "failed to wait for %d blocks", n)

Check warning on line 32 in e2e/runner/zeta.go

View check run for this annotation

Codecov / codecov/patch

e2e/runner/zeta.go#L29-L32

Added lines #L29 - L32 were not covered by tests
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}
func (r *E2ERunner) waitForBlock(n int64) error {
height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{})
if err != nil {
return err

Check warning on line 37 in e2e/runner/zeta.go

View check run for this annotation

Codecov / codecov/patch

e2e/runner/zeta.go#L34-L37

Added lines #L34 - L37 were not covered by tests
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}
if height.Height < n {
return fmt.Errorf("waiting for %d blocks, current height %d", n, height.Height)

Check warning on line 40 in e2e/runner/zeta.go

View check run for this annotation

Codecov / codecov/patch

e2e/runner/zeta.go#L39-L40

Added lines #L39 - L40 were not covered by tests
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}
return nil

Check warning on line 42 in e2e/runner/zeta.go

View check run for this annotation

Codecov / codecov/patch

e2e/runner/zeta.go#L42

Added line #L42 was not covered by tests
}

// WaitForTxReceiptOnZEVM waits for a tx receipt on ZEVM
func (r *E2ERunner) WaitForTxReceiptOnZEVM(tx *ethtypes.Transaction) {
r.Lock()
Expand Down
15 changes: 15 additions & 0 deletions proto/zetachain/zetacore/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ service Query {
option (google.api.http).get = "/zeta-chain/crosschain/inboundTrackers";
}

rpc InboundTracker(QueryInboundTrackerRequest)
returns (QueryInboundTrackerResponse) {
option (google.api.http).get =
"/zeta-chain/crosschain/inboundTracker/{chain_id}/{tx_hash}";
}

// Queries a InboundHashToCctx by index.
rpc InboundHashToCctx(QueryGetInboundHashToCctxRequest)
returns (QueryGetInboundHashToCctxResponse) {
Expand Down Expand Up @@ -383,3 +389,12 @@ message QueryRateLimiterFlagsRequest {}
message QueryRateLimiterFlagsResponse {
RateLimiterFlags rateLimiterFlags = 1 [ (gogoproto.nullable) = false ];
}

message QueryInboundTrackerRequest {
int64 chain_id = 1;
string tx_hash = 2;
}

message QueryInboundTrackerResponse {
InboundTracker inbound_tracker = 1 [ (gogoproto.nullable) = false ];
}
53 changes: 53 additions & 0 deletions typescript/zetachain/zetacore/crosschain/query_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1214,3 +1214,56 @@ export declare class QueryRateLimiterFlagsResponse extends Message<QueryRateLimi
static equals(a: QueryRateLimiterFlagsResponse | PlainMessage<QueryRateLimiterFlagsResponse> | undefined, b: QueryRateLimiterFlagsResponse | PlainMessage<QueryRateLimiterFlagsResponse> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryInboundTrackerRequest
*/
export declare class QueryInboundTrackerRequest extends Message<QueryInboundTrackerRequest> {
/**
* @generated from field: int64 chain_id = 1;
*/
chainId: bigint;

/**
* @generated from field: string tx_hash = 2;
*/
txHash: string;

constructor(data?: PartialMessage<QueryInboundTrackerRequest>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.QueryInboundTrackerRequest";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryInboundTrackerRequest;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryInboundTrackerRequest;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryInboundTrackerRequest;

static equals(a: QueryInboundTrackerRequest | PlainMessage<QueryInboundTrackerRequest> | undefined, b: QueryInboundTrackerRequest | PlainMessage<QueryInboundTrackerRequest> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryInboundTrackerResponse
*/
export declare class QueryInboundTrackerResponse extends Message<QueryInboundTrackerResponse> {
/**
* @generated from field: zetachain.zetacore.crosschain.InboundTracker inbound_tracker = 1;
*/
inboundTracker?: InboundTracker;

constructor(data?: PartialMessage<QueryInboundTrackerResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.QueryInboundTrackerResponse";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryInboundTrackerResponse;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryInboundTrackerResponse;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryInboundTrackerResponse;

static equals(a: QueryInboundTrackerResponse | PlainMessage<QueryInboundTrackerResponse> | undefined, b: QueryInboundTrackerResponse | PlainMessage<QueryInboundTrackerResponse> | undefined): boolean;
}

1 change: 1 addition & 0 deletions x/crosschain/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func GetQueryCmd(_ string) *cobra.Command {
CmdPendingCctx(),
CmdListInboundTrackerByChain(),
CmdListInboundTrackers(),
CmdShowInboundTracker(),
CmdGetZetaAccounting(),
CmdListPendingCCTXWithinRateLimit(),

Expand Down
Loading
Loading