Skip to content

Commit

Permalink
Merge branch 'develop' into e2e-configure-solana-gateway-program_id
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie authored Nov 13, 2024
2 parents 6a65cb8 + d6ed9aa commit 8b7afd8
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 63 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [3137](https://github.com/zeta-chain/node/pull/3137) - remove chain.Chain from zetaclientd config

### Fixes
* [3117](https://github.com/zeta-chain/node/pull/3117) - register messages for emissions module to legacy amino codec.
* [3041](https://github.com/zeta-chain/node/pull/3041) - replace libp2p public DHT with private gossip peer discovery and connection gater for inbound connections
* [3106](https://github.com/zeta-chain/node/pull/3106) - prevent blocked CCTX on out of gas during omnichain calls
* [3139](https://github.com/zeta-chain/node/pull/3139) - fix config resolution in orchestrator
Expand Down
2 changes: 2 additions & 0 deletions e2e/e2etests/test_deploy_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func deployZEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) {
addr, tx, _, err := testdappv2.DeployTestDAppV2(
r.ZEVMAuth,
r.ZEVMClient,
true,
)
if err != nil {
return addr, err
Expand All @@ -64,6 +65,7 @@ func deployEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) {
addr, tx, _, err := testdappv2.DeployTestDAppV2(
r.EVMAuth,
r.EVMClient,
false,
)
if err != nil {
return addr, err
Expand Down
8 changes: 7 additions & 1 deletion e2e/runner/v2_setup_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/big"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
erc20custodyv2 "github.com/zeta-chain/protocol-contracts/v2/pkg/erc20custody.sol"
Expand Down Expand Up @@ -101,7 +102,7 @@ func (r *E2ERunner) SetupEVMV2() {
require.NoError(r, err)

// deploy test dapp v2
testDAppV2Addr, txTestDAppV2, _, err := testdappv2.DeployTestDAppV2(r.EVMAuth, r.EVMClient)
testDAppV2Addr, txTestDAppV2, _, err := testdappv2.DeployTestDAppV2(r.EVMAuth, r.EVMClient, false)
require.NoError(r, err)

r.TestDAppV2EVMAddr = testDAppV2Addr
Expand All @@ -115,6 +116,11 @@ func (r *E2ERunner) SetupEVMV2() {
ensureTxReceipt(txSetCustody, "Set custody in Gateway failed")
ensureTxReceipt(txTestDAppV2, "TestDAppV2 deployment failed")

// check isZetaChain is false
isZetaChain, err := r.TestDAppV2EVM.IsZetaChain(&bind.CallOpts{})
require.NoError(r, err)
require.False(r, isZetaChain)

// whitelist the ERC20
txWhitelist, err := r.ERC20CustodyV2.Whitelist(r.EVMAuth, r.ERC20Addr)
require.NoError(r, err)
Expand Down
8 changes: 7 additions & 1 deletion e2e/runner/v2_setup_zeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package runner
import (
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol"
Expand Down Expand Up @@ -64,7 +65,7 @@ func (r *E2ERunner) SetZEVMContractsV2() {
require.NoError(r, err)

// deploy test dapp v2
testDAppV2Addr, txTestDAppV2, _, err := testdappv2.DeployTestDAppV2(r.ZEVMAuth, r.ZEVMClient)
testDAppV2Addr, txTestDAppV2, _, err := testdappv2.DeployTestDAppV2(r.ZEVMAuth, r.ZEVMClient, true)
require.NoError(r, err)

r.TestDAppV2ZEVMAddr = testDAppV2Addr
Expand All @@ -73,6 +74,11 @@ func (r *E2ERunner) SetZEVMContractsV2() {

ensureTxReceipt(txProxy, "Gateway proxy deployment failed")
ensureTxReceipt(txTestDAppV2, "TestDAppV2 deployment failed")

// check isZetaChain is true
isZetaChain, err := r.TestDAppV2ZEVM.IsZetaChain(&bind.CallOpts{})
require.NoError(r, err)
require.True(r, isZetaChain)
}

// UpdateChainParamsV2Contracts update the erc20 custody contract and gateway address in the chain params
Expand Down
24 changes: 24 additions & 0 deletions pkg/contracts/testdappv2/TestDAppV2.abi
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
[
{
"inputs": [
{
"internalType": "bool",
"name": "isZetaChain_",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "NO_MESSAGE_CALL",
Expand Down Expand Up @@ -143,6 +154,19 @@
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "isZetaChain",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/contracts/testdappv2/TestDAppV2.bin

Large diffs are not rendered by default.

39 changes: 35 additions & 4 deletions pkg/contracts/testdappv2/TestDAppV2.go

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion pkg/contracts/testdappv2/TestDAppV2.json

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions pkg/contracts/testdappv2/TestDAppV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ interface IERC20 {
}

contract TestDAppV2 {
// used to simulate gas consumption
uint256[] private storageArray;

string public constant NO_MESSAGE_CALL = "called with no message";

// define if the chain is ZetaChain
bool immutable public isZetaChain;

struct zContext {
bytes origin;
address sender;
Expand Down Expand Up @@ -37,6 +43,11 @@ contract TestDAppV2 {
mapping(bytes => address) public senderWithMessage;
mapping(bytes32 => uint256) public amountWithMessage;

// the constructor is used to determine if the chain is ZetaChain
constructor(bool isZetaChain_) {
isZetaChain = isZetaChain_;
}

// return the index used for the "WithMessage" mapping when the message for calls is empty
// this allows testing the message with empty message
// this function includes the sender of the message to avoid collisions when running parallel tests with different senders
Expand Down Expand Up @@ -110,6 +121,13 @@ contract TestDAppV2 {

// Revertable interface
function onRevert(RevertContext calldata revertContext) external {

// if the chain is ZetaChain, consume gas to test the gas consumption
// we do it specifically for ZetaChain to test the outbound processing workflow
if (isZetaChain) {
consumeGas();
}

setCalledWithMessage(string(revertContext.revertMessage));
setAmountWithMessage(string(revertContext.revertMessage), 0);
senderWithMessage[revertContext.revertMessage] = revertContext.sender;
Expand All @@ -126,5 +144,21 @@ contract TestDAppV2 {
return "";
}

function consumeGas() internal {
// Approximate target gas consumption
uint256 targetGas = 500000;
// Approximate gas cost for a single storage write
uint256 storageWriteGasCost = 20000;
uint256 iterations = targetGas / storageWriteGasCost;

// Perform the storage writes
for (uint256 i = 0; i < iterations; i++) {
storageArray.push(i);
}

// Reset the storage array to avoid accumulation of storage cost
delete storageArray;
}

receive() external payable {}
}
9 changes: 8 additions & 1 deletion x/emissions/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

func RegisterCodec(_ *codec.LegacyAmino) {
func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgWithdrawEmission{}, "emissions/WithdrawEmission", nil)
cdc.RegisterConcrete(&MsgUpdateParams{}, "emissions/UpdateParams", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgWithdrawEmission{},
&MsgUpdateParams{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

Expand Down
2 changes: 1 addition & 1 deletion x/fungible/keeper/v2_deposits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func getTestDAppNoMessageIndex(

// deployTestDAppV2 deploys the test dapp v2 contract and returns its address
func deployTestDAppV2(t *testing.T, ctx sdk.Context, k *fungiblekeeper.Keeper, evmk types.EVMKeeper) common.Address {
testDAppV2, err := k.DeployContract(ctx, testdappv2.TestDAppV2MetaData)
testDAppV2, err := k.DeployContract(ctx, testdappv2.TestDAppV2MetaData, true)
require.NoError(t, err)
require.NotEmpty(t, testDAppV2)
assertContractDeployment(t, evmk, ctx, testDAppV2)
Expand Down
33 changes: 14 additions & 19 deletions zetaclient/chains/evm/signer/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/zetaclient/testutils/mocks"
)

func TestSigner_SignConnectorOnReceive(t *testing.T) {
ctx := makeCtx(t)

// Setup evm signer
tss := mocks.NewTSSMainnet()
tss := mocks.NewDerivedTSS(chains.BitcoinMainnet)
evmSigner, err := getNewEvmSigner(tss)
require.NoError(t, err)

Expand All @@ -33,8 +34,7 @@ func TestSigner_SignConnectorOnReceive(t *testing.T) {
require.NoError(t, err)

// Verify Signature
tss := mocks.NewTSSMainnet()
verifyTxSignature(t, tx, tss.Pubkey(), evmSigner.EvmSigner())
verifyTxSender(t, tx, tss.EVMAddress(), evmSigner.EvmSigner())
})
t.Run("SignConnectorOnReceive - should fail if keysign fails", func(t *testing.T) {
// Pause tss to make keysign fail
Expand All @@ -53,8 +53,7 @@ func TestSigner_SignConnectorOnReceive(t *testing.T) {
require.NoError(t, err)

// Verify Signature
tss := mocks.NewTSSMainnet()
verifyTxSignature(t, tx, tss.Pubkey(), evmSigner.EvmSigner())
verifyTxSender(t, tx, tss.EVMAddress(), evmSigner.EvmSigner())

// check that by default tx type is legacy tx
assert.Equal(t, ethtypes.LegacyTxType, int(tx.Type()))
Expand Down Expand Up @@ -86,7 +85,7 @@ func TestSigner_SignConnectorOnReceive(t *testing.T) {
require.NoError(t, err)

// ASSERT
verifyTxSignature(t, tx, mocks.NewTSSMainnet().Pubkey(), evmSigner.EvmSigner())
verifyTxSender(t, tx, tss.EVMAddress(), evmSigner.EvmSigner())

// check that by default tx type is a dynamic fee tx
assert.Equal(t, ethtypes.DynamicFeeTxType, int(tx.Type()))
Expand All @@ -101,7 +100,7 @@ func TestSigner_SignConnectorOnRevert(t *testing.T) {
ctx := makeCtx(t)

// Setup evm signer
tss := mocks.NewTSSMainnet()
tss := mocks.NewDerivedTSS(chains.BitcoinMainnet)
evmSigner, err := getNewEvmSigner(tss)
require.NoError(t, err)

Expand All @@ -118,8 +117,7 @@ func TestSigner_SignConnectorOnRevert(t *testing.T) {
require.NoError(t, err)

// Verify tx signature
tss := mocks.NewTSSMainnet()
verifyTxSignature(t, tx, tss.Pubkey(), evmSigner.EvmSigner())
verifyTxSender(t, tx, tss.EVMAddress(), evmSigner.EvmSigner())

// Verify tx body basics
// Note: Revert tx calls connector contract with 0 gas token
Expand All @@ -140,7 +138,7 @@ func TestSigner_SignCancel(t *testing.T) {
ctx := makeCtx(t)

// Setup evm signer
tss := mocks.NewTSSMainnet()
tss := mocks.NewDerivedTSS(chains.BitcoinMainnet)
evmSigner, err := getNewEvmSigner(tss)
require.NoError(t, err)

Expand All @@ -157,12 +155,11 @@ func TestSigner_SignCancel(t *testing.T) {
require.NoError(t, err)

// Verify tx signature
tss := mocks.NewTSSMainnet()
verifyTxSignature(t, tx, tss.Pubkey(), evmSigner.EvmSigner())
verifyTxSender(t, tx, tss.EVMAddress(), evmSigner.EvmSigner())

// Verify tx body basics
// Note: Cancel tx sends 0 gas token to TSS self address
verifyTxBodyBasics(t, tx, evmSigner.TSS().EVMAddress(), txData.nonce, big.NewInt(0))
verifyTxBodyBasics(t, tx, tss.EVMAddress(), txData.nonce, big.NewInt(0))
})
t.Run("SignCancel - should fail if keysign fails", func(t *testing.T) {
// Pause tss to make keysign fail
Expand All @@ -179,7 +176,7 @@ func TestSigner_SignGasWithdraw(t *testing.T) {
ctx := makeCtx(t)

// Setup evm signer
tss := mocks.NewTSSMainnet()
tss := mocks.NewDerivedTSS(chains.BitcoinMainnet)
evmSigner, err := getNewEvmSigner(tss)
require.NoError(t, err)

Expand All @@ -196,8 +193,7 @@ func TestSigner_SignGasWithdraw(t *testing.T) {
require.NoError(t, err)

// Verify tx signature
tss := mocks.NewTSSMainnet()
verifyTxSignature(t, tx, tss.Pubkey(), evmSigner.EvmSigner())
verifyTxSender(t, tx, tss.EVMAddress(), evmSigner.EvmSigner())

// Verify tx body basics
verifyTxBodyBasics(t, tx, txData.to, txData.nonce, txData.amount)
Expand All @@ -217,7 +213,7 @@ func TestSigner_SignERC20Withdraw(t *testing.T) {
ctx := makeCtx(t)

// Setup evm signer
tss := mocks.NewTSSMainnet()
tss := mocks.NewDerivedTSS(chains.BitcoinMainnet)
evmSigner, err := getNewEvmSigner(tss)
require.NoError(t, err)

Expand All @@ -233,8 +229,7 @@ func TestSigner_SignERC20Withdraw(t *testing.T) {
require.NoError(t, err)

// Verify tx signature
tss := mocks.NewTSSMainnet()
verifyTxSignature(t, tx, tss.Pubkey(), evmSigner.EvmSigner())
verifyTxSender(t, tx, tss.EVMAddress(), evmSigner.EvmSigner())

// Verify tx body basics
// Note: Withdraw tx calls erc20 custody contract with 0 gas token
Expand Down
Loading

0 comments on commit 8b7afd8

Please sign in to comment.