From 8be6ce1dc98c275d0fab217cca2c71e154ff4fdd Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Mon, 3 Jun 2024 17:02:45 +0200 Subject: [PATCH 1/6] chore: synchronize v17 changelogs (#2300) --- changelog.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/changelog.md b/changelog.md index d4595d2891..048880a062 100644 --- a/changelog.md +++ b/changelog.md @@ -67,6 +67,13 @@ * [2191](https://github.com/zeta-chain/node/pull/2191) - Fixed conditional logic for the docker build step for non release builds to not overwrite the github tag. * [2192](https://github.com/zeta-chain/node/pull/2192) - Added release status checker and updater pipeline that will update release statuses when they go live on network. +## v17.0.0 + +### Fixes + +* [2249](https://github.com/zeta-chain/node/pull/2249) - fix inbound and outbound validation for BSC chain +* [2265](https://github.com/zeta-chain/node/pull/2265) - fix rate limiter query for revert cctxs + ## v16.0.0 ### Breaking Changes From 833a2536161e5f6075d533f88dc279320f539f7f Mon Sep 17 00:00:00 2001 From: skosito Date: Mon, 3 Jun 2024 16:31:43 +0100 Subject: [PATCH 2/6] feat: initialize cctx gateway interface (#2291) --- app/ante/vesting_test.go | 3 +- app/app.go | 9 ++ changelog.md | 1 + pkg/chains/address_taproot_test.go | 14 +- pkg/crypto/pubkey_test.go | 16 +-- testutil/keeper/crosschain.go | 7 + x/authority/types/genesis_test.go | 2 +- x/crosschain/keeper/cctx_gateway_observers.go | 60 ++++++++ x/crosschain/keeper/cctx_gateway_zevm.go | 100 +++++++++++++ x/crosschain/keeper/initiate_outbound.go | 39 ++++++ ...ound_test.go => initiate_outbound_test.go} | 120 ++++++++++++---- x/crosschain/keeper/keeper.go | 20 ++- .../keeper/msg_server_vote_inbound_tx.go | 9 +- x/crosschain/keeper/process_inbound.go | 131 ------------------ x/crosschain/types/errors.go | 1 + x/fungible/keeper/evm_test.go | 2 +- .../msg_server_deploy_system_contract_test.go | 11 +- x/observer/types/chain_params_test.go | 2 +- .../types/message_disable_cctx_flags_test.go | 4 +- .../types/message_enable_cctx_flags_test.go | 4 +- ...ge_update_gas_price_increase_flags_test.go | 4 +- zetaclient/chains/bitcoin/fee_test.go | 12 +- .../chains/bitcoin/observer/outbound_test.go | 32 ++--- .../chains/bitcoin/signer/signer_test.go | 2 +- zetaclient/chains/evm/validation_test.go | 2 +- 25 files changed, 388 insertions(+), 219 deletions(-) create mode 100644 x/crosschain/keeper/cctx_gateway_observers.go create mode 100644 x/crosschain/keeper/cctx_gateway_zevm.go create mode 100644 x/crosschain/keeper/initiate_outbound.go rename x/crosschain/keeper/{process_inbound_test.go => initiate_outbound_test.go} (81%) delete mode 100644 x/crosschain/keeper/process_inbound.go diff --git a/app/ante/vesting_test.go b/app/ante/vesting_test.go index 280a128ca5..f174bb61c2 100644 --- a/app/ante/vesting_test.go +++ b/app/ante/vesting_test.go @@ -94,8 +94,7 @@ func TestVesting_AnteHandle(t *testing.T) { _, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle) if tt.wantHasErr { - require.Error(t, err) - require.Contains(t, err.Error(), tt.wantErr) + require.ErrorContains(t, err, tt.wantErr) } else { require.NoError(t, err) } diff --git a/app/app.go b/app/app.go index e6dfe90de1..eaad38a8a2 100644 --- a/app/app.go +++ b/app/app.go @@ -105,6 +105,7 @@ import ( "github.com/zeta-chain/zetacore/app/ante" "github.com/zeta-chain/zetacore/docs/openapi" + "github.com/zeta-chain/zetacore/pkg/chains" zetamempool "github.com/zeta-chain/zetacore/pkg/mempool" srvflags "github.com/zeta-chain/zetacore/server/flags" authoritymodule "github.com/zeta-chain/zetacore/x/authority" @@ -597,6 +598,14 @@ func New( app.LightclientKeeper, ) + // initializing map of cctx gateways so crosschain module can decide which one to use + // based on chain info of destination chain + cctxGateways := map[chains.CCTXGateway]crosschainkeeper.CCTXGateway{ + chains.CCTXGateway_observers: crosschainkeeper.NewCCTXGatewayObservers(app.CrosschainKeeper), + chains.CCTXGateway_zevm: crosschainkeeper.NewCCTXGatewayZEVM(app.CrosschainKeeper), + } + app.CrosschainKeeper.SetCCTXGateways(cctxGateways) + // initialize ibccrosschain keeper and set it to the crosschain keeper // there is a circular dependency between the two keepers, crosschain keeper must be initialized first diff --git a/changelog.md b/changelog.md index 048880a062..cc502322d4 100644 --- a/changelog.md +++ b/changelog.md @@ -20,6 +20,7 @@ * [2287](https://github.com/zeta-chain/node/pull/2287) - implement `MsgUpdateChainInfo` message * [2279](https://github.com/zeta-chain/node/pull/2279) - add a CCTXGateway field to chain static data * [2275](https://github.com/zeta-chain/node/pull/2275) - add ChainInfo singleton state variable in authority +* [2291](https://github.com/zeta-chain/node/pull/2291) - initialize cctx gateway interface * [2289](https://github.com/zeta-chain/node/pull/2289) - add an authorization list to keep track of all authorizations on the chain ### Refactor diff --git a/pkg/chains/address_taproot_test.go b/pkg/chains/address_taproot_test.go index 08de704937..c3742dcefc 100644 --- a/pkg/chains/address_taproot_test.go +++ b/pkg/chains/address_taproot_test.go @@ -13,7 +13,7 @@ func TestAddressTaproot(t *testing.T) { // should parse mainnet taproot address addrStr := "bc1p4ur084x8y63mj5hj7eydscuc4awals7ly749x8vhyquc0twcmvhquspa5c" addr, err := DecodeTaprootAddress(addrStr) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, addrStr, addr.String()) require.Equal(t, addrStr, addr.EncodeAddress()) require.True(t, addr.IsForNet(&chaincfg.MainNetParams)) @@ -22,7 +22,7 @@ func TestAddressTaproot(t *testing.T) { // should parse testnet taproot address addrStr := "tb1pzeclkt6upu8xwuksjcz36y4q56dd6jw5r543eu8j8238yaxpvcvq7t8f33" addr, err := DecodeTaprootAddress(addrStr) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, addrStr, addr.String()) require.Equal(t, addrStr, addr.EncodeAddress()) require.True(t, addr.IsForNet(&chaincfg.TestNet3Params)) @@ -31,7 +31,7 @@ func TestAddressTaproot(t *testing.T) { // should parse regtest taproot address addrStr := "bcrt1pqqqsyqcyq5rqwzqfpg9scrgwpugpzysnzs23v9ccrydpk8qarc0sj9hjuh" addr, err := DecodeTaprootAddress(addrStr) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, addrStr, addr.String()) require.Equal(t, addrStr, addr.EncodeAddress()) require.True(t, addr.IsForNet(&chaincfg.RegressionNetParams)) @@ -50,7 +50,7 @@ func TestAddressTaproot(t *testing.T) { witnessProg[i] = byte(i) } _, err := newAddressTaproot("bcrt", witnessProg[:]) - require.Nil(t, err) + require.NoError(t, err) //t.Logf("addr: %v", addr) } { @@ -58,9 +58,9 @@ func TestAddressTaproot(t *testing.T) { // these hex string comes from link // https://mempool.space/tx/41f7cbaaf9a8d378d09ee86de32eebef455225520cb71015cc9a7318fb42e326 witnessProg, err := hex.DecodeString("af06f3d4c726a3b952f2f648d86398af5ddfc3df27aa531d97203987add8db2e") - require.Nil(t, err) + require.NoError(t, err) addr, err := NewAddressTaproot(witnessProg[:], &chaincfg.MainNetParams) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, addr.EncodeAddress(), "bc1p4ur084x8y63mj5hj7eydscuc4awals7ly749x8vhyquc0twcmvhquspa5c") } { @@ -69,7 +69,7 @@ func TestAddressTaproot(t *testing.T) { // https://blockstream.info/tx/09298a2f32f5267f419aeaf8a58c4807dcf6cac3edb59815a3b129cd8f1219b0?expand addrStr := "bc1p6pls9gpm24g8ntl37pajpjtuhd3y08hs5rnf9a4n0wq595hwdh9suw7m2h" addr, err := DecodeTaprootAddress(addrStr) - require.Nil(t, err) + require.NoError(t, err) require.Equal( t, "d07f02a03b555079aff1f07b20c97cbb62479ef0a0e692f6b37b8142d2ee6dcb", diff --git a/pkg/crypto/pubkey_test.go b/pkg/crypto/pubkey_test.go index 8f1a46f393..5f16f8142e 100644 --- a/pkg/crypto/pubkey_test.go +++ b/pkg/crypto/pubkey_test.go @@ -207,15 +207,15 @@ func TestNewPubKey(t *testing.T) { t.Run("should create new pub key from string", func(t *testing.T) { _, pubKey, _ := testdata.KeyTestPubAddr() spk, err := cosmos.Bech32ifyPubKey(cosmos.Bech32PubKeyTypeAccPub, pubKey) - require.Nil(t, err) + require.NoError(t, err) pk, err := NewPubKey(spk) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, PubKey(spk), pk) }) t.Run("should return empty pub key from empty string", func(t *testing.T) { pk, err := NewPubKey("") - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, EmptyPubKey, pk) }) @@ -230,9 +230,9 @@ func TestGetAddressFromPubkeyString(t *testing.T) { t.Run("should get address from pubkey string", func(t *testing.T) { _, pubKey, _ := testdata.KeyTestPubAddr() spk, err := cosmos.Bech32ifyPubKey(cosmos.Bech32PubKeyTypeAccPub, pubKey) - require.Nil(t, err) + require.NoError(t, err) _, err = GetAddressFromPubkeyString(spk) - require.Nil(t, err) + require.NoError(t, err) }) t.Run("should get address from nonbech32 string", func(t *testing.T) { @@ -349,7 +349,7 @@ func TestGetEVMAddress(t *testing.T) { t.Run("should return empty if pubkey is empty", func(t *testing.T) { pubKey := PubKey("") e, err := pubKey.GetEVMAddress() - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, chains.NoAddress, e) }) @@ -359,13 +359,13 @@ func TestGetEVMAddress(t *testing.T) { pk, _ := NewPubKey(spk) _, err := pk.GetEVMAddress() - require.Nil(t, err) + require.NoError(t, err) }) t.Run("should error if non bech32", func(t *testing.T) { pk := PubKey("invalid") e, err := pk.GetEVMAddress() - require.NotNil(t, err) + require.ErrorContains(t, err, "decoding bech32 failed") require.Equal(t, chains.NoAddress, e) }) } diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index 0ff22a6250..5ca5acbaae 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -174,6 +174,13 @@ func CrosschainKeeperWithMocks( lightclientKeeper, ) + cctxGateways := map[chains.CCTXGateway]keeper.CCTXGateway{ + chains.CCTXGateway_observers: keeper.NewCCTXGatewayObservers(*k), + chains.CCTXGateway_zevm: keeper.NewCCTXGatewayZEVM(*k), + } + + k.SetCCTXGateways(cctxGateways) + // initialize ibccrosschain keeper and set it to the crosschain keeper // there is a circular dependency between the two keepers, crosschain keeper must be initialized first diff --git a/x/authority/types/genesis_test.go b/x/authority/types/genesis_test.go index 90aee92509..3d8dcd14df 100644 --- a/x/authority/types/genesis_test.go +++ b/x/authority/types/genesis_test.go @@ -72,7 +72,7 @@ func TestGenesisState_Validate(t *testing.T) { err := tt.gs.Validate() if tt.errContains != "" { require.Error(t, err) - require.Contains(t, err.Error(), tt.errContains) + require.ErrorContains(t, err, tt.errContains) } else { require.NoError(t, err) } diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go new file mode 100644 index 0000000000..556d242214 --- /dev/null +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -0,0 +1,60 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +// CCTXGatewayObservers is implementation of CCTXGateway interface for observers +type CCTXGatewayObservers struct { + crosschainKeeper Keeper +} + +// NewCCTXGatewayObservers returns new instance of CCTXGatewayObservers +func NewCCTXGatewayObservers(crosschainKeeper Keeper) CCTXGatewayObservers { + return CCTXGatewayObservers{ + crosschainKeeper: crosschainKeeper, + } +} + +/* +InitiateOutbound updates the store so observers can use the PendingCCTX query: + + - If preprocessing of outbound is successful, the CCTX status is changed to PendingOutbound. + + - if preprocessing of outbound, such as paying the gas fee for the destination fails, the state is reverted to aborted + + We do not return an error from this function, as all changes need to be persisted to the state. + + Instead, we use a temporary context to make changes and then commit the context on for the happy path, i.e cctx is set to PendingOutbound. + New CCTX status after preprocessing is returned. +*/ +func (c CCTXGatewayObservers) InitiateOutbound( + ctx sdk.Context, + cctx *types.CrossChainTx, +) (newCCTXStatus types.CctxStatus) { + tmpCtx, commit := ctx.CacheContext() + outboundReceiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId + err := func() error { + err := c.crosschainKeeper.PayGasAndUpdateCctx( + tmpCtx, + outboundReceiverChainID, + cctx, + cctx.InboundParams.Amount, + false, + ) + if err != nil { + return err + } + return c.crosschainKeeper.UpdateNonce(tmpCtx, outboundReceiverChainID, cctx) + }() + if err != nil { + // do not commit anything here as the CCTX should be aborted + cctx.SetAbort(err.Error()) + return types.CctxStatus_Aborted + } + commit() + cctx.SetPendingOutbound("") + return types.CctxStatus_PendingOutbound +} diff --git a/x/crosschain/keeper/cctx_gateway_zevm.go b/x/crosschain/keeper/cctx_gateway_zevm.go new file mode 100644 index 0000000000..89e7c5a152 --- /dev/null +++ b/x/crosschain/keeper/cctx_gateway_zevm.go @@ -0,0 +1,100 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +// CCTXGatewayZEVM is implementation of CCTXGateway interface for ZEVM +type CCTXGatewayZEVM struct { + crosschainKeeper Keeper +} + +// NewCCTXGatewayZEVM returns new instance of CCTXGatewayZEVM +func NewCCTXGatewayZEVM(crosschainKeeper Keeper) CCTXGatewayZEVM { + return CCTXGatewayZEVM{ + crosschainKeeper: crosschainKeeper, + } +} + +/* +InitiateOutbound handles evm deposit and call ValidateOutbound. +TODO (https://github.com/zeta-chain/node/issues/2278): move remaining of this comment to ValidateOutbound once it's added. + + - If the deposit is successful, the CCTX status is changed to OutboundMined. + + - If the deposit returns an internal error i.e if HandleEVMDeposit() returns an error, but isContractReverted is false, the CCTX status is changed to Aborted. + + - If the deposit is reverted, the function tries to create a revert cctx with status PendingRevert. + + - If the creation of revert tx also fails it changes the status to Aborted. + +Note : Aborted CCTXs are not refunded in this function. The refund is done using a separate refunding mechanism. +We do not return an error from this function , as all changes need to be persisted to the state. +Instead we use a temporary context to make changes and then commit the context on for the happy path ,i.e cctx is set to OutboundMined. +New CCTX status after preprocessing is returned. +*/ +func (c CCTXGatewayZEVM) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) (newCCTXStatus types.CctxStatus) { + tmpCtx, commit := ctx.CacheContext() + isContractReverted, err := c.crosschainKeeper.HandleEVMDeposit(tmpCtx, cctx) + + // TODO (https://github.com/zeta-chain/node/issues/2278): further processing will be in validateOutbound(...), for now keeping it here + if err != nil && !isContractReverted { + // exceptional case; internal error; should abort CCTX + cctx.SetAbort(err.Error()) + return types.CctxStatus_Aborted + } else if err != nil && isContractReverted { + // contract call reverted; should refund via a revert tx + revertMessage := err.Error() + senderChain := c.crosschainKeeper.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, cctx.InboundParams.SenderChainId) + if senderChain == nil { + cctx.SetAbort(fmt.Sprintf("invalid sender chain id %d", cctx.InboundParams.SenderChainId)) + return types.CctxStatus_Aborted + } + gasLimit, err := c.crosschainKeeper.GetRevertGasLimit(ctx, *cctx) + if err != nil { + cctx.SetAbort(fmt.Sprintf("revert gas limit error: %s", err.Error())) + return types.CctxStatus_Aborted + } + if gasLimit == 0 { + // use same gas limit of outbound as a fallback -- should not be required + gasLimit = cctx.GetCurrentOutboundParam().GasLimit + } + + err = cctx.AddRevertOutbound(gasLimit) + if err != nil { + cctx.SetAbort(fmt.Sprintf("revert outbound error: %s", err.Error())) + return types.CctxStatus_Aborted + } + // we create a new cached context, and we don't commit the previous one with EVM deposit + tmpCtxRevert, commitRevert := ctx.CacheContext() + err = func() error { + err := c.crosschainKeeper.PayGasAndUpdateCctx( + tmpCtxRevert, + senderChain.ChainId, + cctx, + cctx.InboundParams.Amount, + false, + ) + if err != nil { + return err + } + // Update nonce using senderchain id as this is a revert tx and would go back to the original sender + return c.crosschainKeeper.UpdateNonce(tmpCtxRevert, senderChain.ChainId, cctx) + }() + if err != nil { + cctx.SetAbort(fmt.Sprintf("deposit revert message: %s err : %s", revertMessage, err.Error())) + return types.CctxStatus_Aborted + } + commitRevert() + cctx.SetPendingRevert(revertMessage) + return types.CctxStatus_PendingRevert + } + // successful HandleEVMDeposit; + commit() + cctx.SetOutBoundMined("Remote omnichain contract call completed") + return types.CctxStatus_OutboundMined +} diff --git a/x/crosschain/keeper/initiate_outbound.go b/x/crosschain/keeper/initiate_outbound.go new file mode 100644 index 0000000000..8174f6ec4e --- /dev/null +++ b/x/crosschain/keeper/initiate_outbound.go @@ -0,0 +1,39 @@ +package keeper + +import ( + "fmt" + + cosmoserrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +// InitiateOutbound initiates the outbound for the CCTX depending on the CCTX gateway. +// It does a conditional dispatch to correct CCTX gateway based on the receiver chain +// which handles the state changes and error handling. +func (k Keeper) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) (types.CctxStatus, error) { + receiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId + chainInfo := chains.GetChainFromChainID(receiverChainID) + if chainInfo == nil { + return cctx.CctxStatus.Status, cosmoserrors.Wrap( + types.ErrInitiatitingOutbound, + fmt.Sprintf( + "chain info not found for %d", receiverChainID, + ), + ) + } + + cctxGateway, ok := k.cctxGateways[chainInfo.CctxGateway] + if !ok { + return cctx.CctxStatus.Status, cosmoserrors.Wrap( + types.ErrInitiatitingOutbound, + fmt.Sprintf( + "CCTXGateway not defined for receiver chain %d", receiverChainID, + ), + ) + } + + return cctxGateway.InitiateOutbound(ctx, cctx), nil +} diff --git a/x/crosschain/keeper/process_inbound_test.go b/x/crosschain/keeper/initiate_outbound_test.go similarity index 81% rename from x/crosschain/keeper/process_inbound_test.go rename to x/crosschain/keeper/initiate_outbound_test.go index 0286290cc4..59d0eaee0b 100644 --- a/x/crosschain/keeper/process_inbound_test.go +++ b/x/crosschain/keeper/initiate_outbound_test.go @@ -13,12 +13,13 @@ import ( "github.com/zeta-chain/zetacore/pkg/coin" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/crosschain/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { +func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { t.Run("process zevm deposit successfully", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseFungibleMock: true, @@ -34,7 +35,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { mock.Anything, receiver, int64(0), amount, mock.Anything, mock.Anything).Return(nil, nil) - // call ProcessInbound + // call InitiateOutbound cctx := sample.CrossChainTx(t, "test") cctx.CctxStatus = &types.Status{Status: types.CctxStatus_PendingInbound} cctx.GetCurrentOutboundParam().Receiver = receiver.String() @@ -42,8 +43,10 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { cctx.GetInboundParams().Amount = sdkmath.NewUintFromBigInt(amount) cctx.InboundParams.CoinType = coin.CoinType_Zeta cctx.GetInboundParams().SenderChainId = 0 - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_OutboundMined, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_OutboundMined, newStatus) }) t.Run("unable to process zevm deposit HandleEVMDeposit returns err without reverting", func(t *testing.T) { @@ -61,7 +64,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { fungibleMock.On("ZETADepositAndCallContract", mock.Anything, mock.Anything, receiver, int64(0), amount, mock.Anything, mock.Anything). Return(nil, fmt.Errorf("deposit error")) - // call ProcessInbound + // call InitiateOutbound cctx := sample.CrossChainTx(t, "test") cctx.CctxStatus = &types.Status{Status: types.CctxStatus_PendingInbound} cctx.GetCurrentOutboundParam().Receiver = receiver.String() @@ -69,8 +72,10 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { cctx.GetInboundParams().Amount = sdkmath.NewUintFromBigInt(amount) cctx.InboundParams.CoinType = coin.CoinType_Zeta cctx.GetInboundParams().SenderChainId = 0 - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal(t, "deposit error", cctx.CctxStatus.StatusMessage) }) @@ -98,11 +103,13 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId). Return(nil) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, "", amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal( t, fmt.Sprintf("invalid sender chain id %d", cctx.InboundParams.SenderChainId), @@ -136,11 +143,13 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { fungibleMock.On("GetForeignCoinFromAsset", mock.Anything, asset, senderChain.ChainId). Return(fungibletypes.ForeignCoins{}, false) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal( t, fmt.Sprintf("revert gas limit error: %s", types.ErrForeignCoinNotFound), @@ -179,11 +188,13 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId). Return(nil).Once() - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal( t, fmt.Sprintf("deposit revert message: %s err : %s", errDeposit, observertypes.ErrSupportedChains), @@ -223,11 +234,13 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId). Return(nil).Once() - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal( t, fmt.Sprintf("deposit revert message: %s err : %s", errDeposit, observertypes.ErrSupportedChains), @@ -268,11 +281,13 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock.On("GetChainNonces", mock.Anything, senderChain.ChainName.String()). Return(observertypes.ChainNonces{}, false) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Contains(t, cctx.CctxStatus.StatusMessage, "cannot find receiver chain nonce") }) @@ -306,11 +321,13 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { // mock successful UpdateNonce updatedNonce := keepertest.MockUpdateNonce(observerMock, *senderChain) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_PendingRevert, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_PendingRevert, newStatus) require.Equal(t, errDeposit.Error(), cctx.CctxStatus.StatusMessage) require.Equal(t, updatedNonce, cctx.GetCurrentOutboundParam().TssNonce) }) @@ -342,12 +359,14 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { // mock successful GetRevertGasLimit for ERC20 keepertest.MockGetRevertGasLimitForERC20(fungibleMock, asset, *senderChain, 100) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId cctx.OutboundParams = append(cctx.OutboundParams, cctx.GetCurrentOutboundParam()) - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Contains( t, cctx.CctxStatus.StatusMessage, @@ -357,7 +376,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { ) } -func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { +func TestKeeper_InitiateOutboundProcessCrosschainMsgPassing(t *testing.T) { t.Run("process crosschain msg passing successfully", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseFungibleMock: true, @@ -377,10 +396,12 @@ func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { // mock successful UpdateNonce updatedNonce := keepertest.MockUpdateNonce(observerMock, *receiverChain) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_PendingOutbound, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_PendingOutbound, newStatus) require.Equal(t, updatedNonce, cctx.GetCurrentOutboundParam().TssNonce) }) @@ -400,10 +421,12 @@ func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, receiverChain.ChainId). Return(nil).Once() - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal(t, observertypes.ErrSupportedChains.Error(), cctx.CctxStatus.StatusMessage) }) @@ -427,10 +450,55 @@ func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { observerMock.On("GetChainNonces", mock.Anything, receiverChain.ChainName.String()). Return(observertypes.ChainNonces{}, false) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - k.ProcessInbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Contains(t, cctx.CctxStatus.StatusMessage, "cannot find receiver chain nonce") }) } + +func TestKeeper_InitiateOutboundFailures(t *testing.T) { + t.Run("should fail if chain info can not be found for receiver chain id", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseFungibleMock: true, + UseObserverMock: true, + }) + + // Setup mock data + receiver := sample.EthAddress() + amount := big.NewInt(42) + receiverChain := getValidEthChain() + receiverChain.ChainId = 123 + // call InitiateOutbound + cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.Error(t, err) + require.Equal(t, types.CctxStatus_PendingInbound, newStatus) + require.ErrorContains(t, err, "chain info not found") + }) + + t.Run("should fail if cctx gateway not found for receiver chain id", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseFungibleMock: true, + UseObserverMock: true, + }) + + // reset cctx gateways + k.SetCCTXGateways(map[chains.CCTXGateway]keeper.CCTXGateway{}) + + // Setup mock data + receiver := sample.EthAddress() + amount := big.NewInt(42) + receiverChain := getValidEthChain() + // call InitiateOutbound + cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.Equal(t, types.CctxStatus_PendingInbound, newStatus) + require.NotNil(t, err) + require.ErrorContains(t, err, "CCTXGateway not defined for receiver chain") + }) + +} diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index fc483689b3..b32543126c 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -8,14 +8,24 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/x/crosschain/types" ) +// CCTXGateway is interface implemented by every gateway. It is one of interfaces used for communication +// between CCTX gateways and crosschain module, and it is called by crosschain module. +type CCTXGateway interface { + // Initiate a new outbound, this tells the CCTXGateway to carry out the action to execute the outbound. + // It is the only entry point to initiate an outbound and it returns new CCTX status after it is completed. + InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) (newCCTXStatus types.CctxStatus) +} + type ( Keeper struct { - cdc codec.Codec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey + cdc codec.Codec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + cctxGateways map[chains.CCTXGateway]CCTXGateway stakingKeeper types.StakingKeeper authKeeper types.AccountKeeper @@ -100,6 +110,10 @@ func (k *Keeper) SetIBCCrosschainKeeper(ibcCrosschainKeeper types.IBCCrosschainK k.ibcCrosschainKeeper = ibcCrosschainKeeper } +func (k *Keeper) SetCCTXGateways(cctxGateways map[chains.CCTXGateway]CCTXGateway) { + k.cctxGateways = cctxGateways +} + func (k Keeper) GetStoreKey() storetypes.StoreKey { return k.storeKey } diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx.go b/x/crosschain/keeper/msg_server_vote_inbound_tx.go index 9b40097635..b118d2bc43 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx.go @@ -106,9 +106,12 @@ func (k msgServer) VoteInbound( if err != nil { return nil, err } - // Process the inbound CCTX, the process function manages the state commit and cctx status change. - // If the process fails, the changes to the evm state are rolled back. - k.ProcessInbound(ctx, &cctx) + // Initiate outbound, the process function manages the state commit and cctx status change. + // If the process fails, the changes to the evm state are rolled back. + _, err = k.InitiateOutbound(ctx, &cctx) + if err != nil { + return nil, err + } // Save the inbound CCTX to the store. This is called irrespective of the status of the CCTX or the outcome of the process function. k.SaveInbound(ctx, &cctx, msg.EventIndex) return &types.MsgVoteInboundResponse{}, nil diff --git a/x/crosschain/keeper/process_inbound.go b/x/crosschain/keeper/process_inbound.go deleted file mode 100644 index 2fe9bfb3c9..0000000000 --- a/x/crosschain/keeper/process_inbound.go +++ /dev/null @@ -1,131 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/x/crosschain/types" -) - -// ProcessInbound processes the inbound CCTX. -// It does a conditional dispatch to ProcessZEVMDeposit or ProcessCrosschainMsgPassing based on the receiver chain. -// The internal functions handle the state changes and error handling. -func (k Keeper) ProcessInbound(ctx sdk.Context, cctx *types.CrossChainTx) { - if chains.IsZetaChain(cctx.GetCurrentOutboundParam().ReceiverChainId) { - k.processZEVMDeposit(ctx, cctx) - } else { - k.processCrosschainMsgPassing(ctx, cctx) - } -} - -/* -processZEVMDeposit processes the EVM deposit CCTX. A deposit is a cctx which has Zetachain as the receiver chain.It trasnsitions state according to the following rules: - - - If the deposit is successful, the CCTX status is changed to OutboundMined. - - - If the deposit returns an internal error i.e if HandleEVMDeposit() returns an error, but isContractReverted is false, the CCTX status is changed to Aborted. - - - If the deposit is reverted, the function tries to create a revert cctx with status PendingRevert. - - - If the creation of revert tx also fails it changes the status to Aborted. - -Note : Aborted CCTXs are not refunded in this function. The refund is done using a separate refunding mechanism. -We do not return an error from this function , as all changes need to be persisted to the state. -Instead we use a temporary context to make changes and then commit the context on for the happy path ,i.e cctx is set to OutboundMined. -*/ -func (k Keeper) processZEVMDeposit(ctx sdk.Context, cctx *types.CrossChainTx) { - tmpCtx, commit := ctx.CacheContext() - isContractReverted, err := k.HandleEVMDeposit(tmpCtx, cctx) - - if err != nil && !isContractReverted { // exceptional case; internal error; should abort CCTX - cctx.SetAbort(err.Error()) - return - } else if err != nil && isContractReverted { // contract call reverted; should refund via a revert tx - revertMessage := err.Error() - senderChain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, cctx.InboundParams.SenderChainId) - if senderChain == nil { - cctx.SetAbort(fmt.Sprintf("invalid sender chain id %d", cctx.InboundParams.SenderChainId)) - return - } - gasLimit, err := k.GetRevertGasLimit(ctx, *cctx) - if err != nil { - cctx.SetAbort(fmt.Sprintf("revert gas limit error: %s", err.Error())) - return - } - if gasLimit == 0 { - // use same gas limit of outbound as a fallback -- should not be required - gasLimit = cctx.GetCurrentOutboundParam().GasLimit - } - - err = cctx.AddRevertOutbound(gasLimit) - if err != nil { - cctx.SetAbort(fmt.Sprintf("revert outbound error: %s", err.Error())) - return - } - // we create a new cached context, and we don't commit the previous one with EVM deposit - tmpCtxRevert, commitRevert := ctx.CacheContext() - err = func() error { - err := k.PayGasAndUpdateCctx( - tmpCtxRevert, - senderChain.ChainId, - cctx, - cctx.InboundParams.Amount, - false, - ) - if err != nil { - return err - } - // Update nonce using senderchain id as this is a revert tx and would go back to the original sender - return k.UpdateNonce(tmpCtxRevert, senderChain.ChainId, cctx) - }() - if err != nil { - cctx.SetAbort(fmt.Sprintf("deposit revert message: %s err : %s", revertMessage, err.Error())) - return - } - commitRevert() - cctx.SetPendingRevert(revertMessage) - return - } - // successful HandleEVMDeposit; - commit() - cctx.SetOutBoundMined("Remote omnichain contract call completed") - return -} - -/* -processCrosschainMsgPassing processes the CCTX for crosschain message passing. A crosschain message passing is a cctx which has a non-Zetachain as the receiver chain.It trasnsitions state according to the following rules: - - - If the crosschain message passing is successful, the CCTX status is changed to PendingOutbound. - - - If the crosschain message passing returns an error, the CCTX status is changed to Aborted. - We do not return an error from this function, as all changes need to be persisted to the state. - - Instead, we use a temporary context to make changes and then commit the context on for the happy path ,i.e cctx is set to PendingOutbound. -*/ -func (k Keeper) processCrosschainMsgPassing(ctx sdk.Context, cctx *types.CrossChainTx) { - tmpCtx, commit := ctx.CacheContext() - outboundReceiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId - err := func() error { - err := k.PayGasAndUpdateCctx( - tmpCtx, - outboundReceiverChainID, - cctx, - cctx.InboundParams.Amount, - false, - ) - if err != nil { - return err - } - return k.UpdateNonce(tmpCtx, outboundReceiverChainID, cctx) - }() - if err != nil { - // do not commit anything here as the CCTX should be aborted - cctx.SetAbort(err.Error()) - return - } - commit() - cctx.SetPendingOutbound("") - return -} diff --git a/x/crosschain/types/errors.go b/x/crosschain/types/errors.go index ffeda3077c..232bf229db 100644 --- a/x/crosschain/types/errors.go +++ b/x/crosschain/types/errors.go @@ -48,4 +48,5 @@ var ( ErrUnableToDecodeMessageString = errorsmod.Register(ModuleName, 1151, "unable to decode message string") ErrInvalidRateLimiterFlags = errorsmod.Register(ModuleName, 1152, "invalid rate limiter flags") ErrMaxTxOutTrackerHashesReached = errorsmod.Register(ModuleName, 1153, "max tx out tracker hashes reached") + ErrInitiatitingOutbound = errorsmod.Register(ModuleName, 1154, "cannot initiate outbound") ) diff --git a/x/fungible/keeper/evm_test.go b/x/fungible/keeper/evm_test.go index a175943247..2ef0f4dfb9 100644 --- a/x/fungible/keeper/evm_test.go +++ b/x/fungible/keeper/evm_test.go @@ -575,7 +575,7 @@ func TestKeeper_CallEVMWithData(t *testing.T) { // check reason is included for revert error // 0xbfb4ebcf is the hash of "Foo()" - require.Contains(t, err.Error(), "reason: 0xbfb4ebcf") + require.ErrorContains(t, err, "reason: 0xbfb4ebcf") res, err = k.CallEVM( ctx, diff --git a/x/fungible/keeper/msg_server_deploy_system_contract_test.go b/x/fungible/keeper/msg_server_deploy_system_contract_test.go index 6b11c46592..117ee0cc33 100644 --- a/x/fungible/keeper/msg_server_deploy_system_contract_test.go +++ b/x/fungible/keeper/msg_server_deploy_system_contract_test.go @@ -72,8 +72,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { mockFailedContractDeployment(ctx, t, k) _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) - require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) t.Run("should fail if wzeta contract deployment fails", func(t *testing.T) { @@ -95,7 +94,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) t.Run("should fail if uniswapv2router deployment fails", func(t *testing.T) { @@ -118,7 +117,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) t.Run("should fail if connectorzevm deployment fails", func(t *testing.T) { @@ -142,7 +141,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) t.Run("should fail if system contract deployment fails", func(t *testing.T) { @@ -167,7 +166,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) } diff --git a/x/observer/types/chain_params_test.go b/x/observer/types/chain_params_test.go index 9aab9dc9ff..1703b43f54 100644 --- a/x/observer/types/chain_params_test.go +++ b/x/observer/types/chain_params_test.go @@ -30,7 +30,7 @@ func TestChainParamsList_Validate(t *testing.T) { list.ChainParams = append(list.ChainParams, list.ChainParams[0]) err := list.Validate() require.Error(t, err) - require.Contains(t, err.Error(), "duplicated chain id") + require.ErrorContains(t, err, "duplicated chain id") }) } diff --git a/x/observer/types/message_disable_cctx_flags_test.go b/x/observer/types/message_disable_cctx_flags_test.go index 40a4d023d2..8a394a2bac 100644 --- a/x/observer/types/message_disable_cctx_flags_test.go +++ b/x/observer/types/message_disable_cctx_flags_test.go @@ -20,14 +20,14 @@ func TestMsgDisableCCTX_ValidateBasic(t *testing.T) { name: "invalid creator address", msg: types.NewMsgDisableCCTX("invalid", true, true), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "invalid creator address") + require.ErrorContains(t, err, "invalid creator address") }, }, { name: "invalid flags", msg: types.NewMsgDisableCCTX(sample.AccAddress(), false, false), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "at least one of DisableInbound or DisableOutbound must be true") + require.ErrorContains(t, err, "at least one of DisableInbound or DisableOutbound must be true") }, }, { diff --git a/x/observer/types/message_enable_cctx_flags_test.go b/x/observer/types/message_enable_cctx_flags_test.go index 2033837e7d..f1121c5fce 100644 --- a/x/observer/types/message_enable_cctx_flags_test.go +++ b/x/observer/types/message_enable_cctx_flags_test.go @@ -20,14 +20,14 @@ func TestMsgEnableCCTX_ValidateBasic(t *testing.T) { name: "invalid creator address", msg: types.NewMsgEnableCCTX("invalid", true, true), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "invalid creator address") + require.ErrorContains(t, err, "invalid creator address") }, }, { name: "invalid flags", msg: types.NewMsgEnableCCTX(sample.AccAddress(), false, false), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "at least one of EnableInbound or EnableOutbound must be true") + require.ErrorContains(t, err, "at least one of EnableInbound or EnableOutbound must be true") }, }, { diff --git a/x/observer/types/message_update_gas_price_increase_flags_test.go b/x/observer/types/message_update_gas_price_increase_flags_test.go index d432835b62..17f110958c 100644 --- a/x/observer/types/message_update_gas_price_increase_flags_test.go +++ b/x/observer/types/message_update_gas_price_increase_flags_test.go @@ -20,7 +20,7 @@ func TestMsgUpdateGasPriceIncreaseFlags_ValidateBasic(t *testing.T) { name: "invalid creator address", msg: types.NewMsgUpdateGasPriceIncreaseFlags("invalid", types.DefaultGasPriceIncreaseFlags), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "invalid creator address") + require.ErrorContains(t, err, "invalid creator address") }, }, { @@ -34,7 +34,7 @@ func TestMsgUpdateGasPriceIncreaseFlags_ValidateBasic(t *testing.T) { }, ), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "invalid request") + require.ErrorContains(t, err, "invalid request") }, }, { diff --git a/zetaclient/chains/bitcoin/fee_test.go b/zetaclient/chains/bitcoin/fee_test.go index bb6757ede2..160bdf6093 100644 --- a/zetaclient/chains/bitcoin/fee_test.go +++ b/zetaclient/chains/bitcoin/fee_test.go @@ -60,13 +60,13 @@ var exampleTxids = []string{ func generateKeyPair(t *testing.T, net *chaincfg.Params) (*btcec.PrivateKey, btcutil.Address, []byte) { privateKey, err := btcec.NewPrivateKey(btcec.S256()) - require.Nil(t, err) + require.NoError(t, err) pubKeyHash := btcutil.Hash160(privateKey.PubKey().SerializeCompressed()) addr, err := btcutil.NewAddressWitnessPubKeyHash(pubKeyHash, net) - require.Nil(t, err) + require.NoError(t, err) //fmt.Printf("New address: %s\n", addr.EncodeAddress()) pkScript, err := PayToAddrScript(addr) - require.Nil(t, err) + require.NoError(t, err) return privateKey, addr, pkScript } @@ -98,7 +98,7 @@ func addTxInputs(t *testing.T, tx *wire.MsgTx, txids []string) { preTxSize := tx.SerializeSize() for _, txid := range txids { hash, err := chainhash.NewHashFromStr(txid) - require.Nil(t, err) + require.NoError(t, err) outpoint := wire.NewOutPoint(hash, uint32(rand.Intn(100))) txIn := wire.NewTxIn(outpoint, nil, nil) tx.AddTxIn(txIn) @@ -158,9 +158,9 @@ func signTx(t *testing.T, tx *wire.MsgTx, payerScript []byte, privateKey *btcec. for ix := range tx.TxIn { amount := int64(1 + rand.Intn(100000000)) witnessHash, err := txscript.CalcWitnessSigHash(payerScript, sigHashes, txscript.SigHashAll, tx, ix, amount) - require.Nil(t, err) + require.NoError(t, err) sig, err := privateKey.Sign(witnessHash) - require.Nil(t, err) + require.NoError(t, err) pkCompressed := privateKey.PubKey().SerializeCompressed() txWitness := wire.TxWitness{append(sig.Serialize(), byte(txscript.SigHashAll)), pkCompressed} diff --git a/zetaclient/chains/bitcoin/observer/outbound_test.go b/zetaclient/chains/bitcoin/observer/outbound_test.go index 2f25575284..bad0997c0c 100644 --- a/zetaclient/chains/bitcoin/observer/outbound_test.go +++ b/zetaclient/chains/bitcoin/observer/outbound_test.go @@ -33,7 +33,7 @@ func MockBTCObserverMainnet() *Observer { func createObserverWithPrivateKey(t *testing.T) *Observer { skHex := "7b8507ba117e069f4a3f456f505276084f8c92aee86ac78ae37b4d1801d35fa8" privateKey, err := crypto.HexToECDSA(skHex) - require.Nil(t, err) + require.NoError(t, err) tss := &mocks.TSS{ PrivKey: privateKey, } @@ -241,7 +241,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.01, nonce = 0 // output: [0.01], 0.01 result, amount, _, _, err := ob.SelectUTXOs(0.01, 5, 0, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 0.01, amount) require.Equal(t, ob.utxos[0:1], result) @@ -249,7 +249,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.5, nonce = 1 // output: error result, amount, _, _, err = ob.SelectUTXOs(0.5, 5, 1, math.MaxUint16, true) - require.NotNil(t, err) + require.Error(t, err) require.Nil(t, result) require.Zero(t, amount) require.Equal(t, "getOutboundIDByNonce: cannot find outbound txid for nonce 0", err.Error()) @@ -259,7 +259,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.5, nonce = 1 // output: [0.00002, 0.01, 0.12, 0.18, 0.24], 0.55002 result, amount, _, _, err = ob.SelectUTXOs(0.5, 5, 1, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 0.55002, amount) require.Equal(t, ob.utxos[0:5], result) mineTxNSetNonceMark(ob, 1, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 1 @@ -268,7 +268,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 1.0, nonce = 2 // output: [0.00002001, 0.01, 0.12, 0.18, 0.24, 0.5], 1.05002001 result, amount, _, _, err = ob.SelectUTXOs(1.0, 5, 2, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 1.05002001, amount, 1e-8) require.Equal(t, ob.utxos[0:6], result) mineTxNSetNonceMark(ob, 2, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 2 @@ -277,7 +277,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 8.05, nonce = 3 // output: [0.00002002, 0.24, 0.5, 1.26, 2.97, 3.28], 8.25002002 result, amount, _, _, err = ob.SelectUTXOs(8.05, 5, 3, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 8.25002002, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[0]}, ob.utxos[4:9]...) require.Equal(t, expected, result) @@ -287,7 +287,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.503, nonce = 24105432 // output: [0.24107432, 0.01, 0.12, 0.18, 0.24], 0.55002002 result, amount, _, _, err = ob.SelectUTXOs(0.503, 5, 24105432, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 0.79107431, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:4]...) require.Equal(t, expected, result) @@ -297,7 +297,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 1.0, nonce = 24105433 // output: [0.24107432, 0.12, 0.18, 0.24, 0.5], 1.28107432 result, amount, _, _, err = ob.SelectUTXOs(1.0, 5, 24105433, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 1.28107432, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[1:4]...) expected = append(expected, ob.utxos[5]) @@ -307,7 +307,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 16.03 // output: [0.24107432, 1.26, 2.97, 3.28, 5.16, 8.72], 21.63107432 result, amount, _, _, err = ob.SelectUTXOs(16.03, 5, 24105433, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 21.63107432, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[6:11]...) require.Equal(t, expected, result) @@ -316,7 +316,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 21.64 // output: error result, amount, _, _, err = ob.SelectUTXOs(21.64, 5, 24105433, math.MaxUint16, true) - require.NotNil(t, err) + require.Error(t, err) require.Nil(t, result) require.Zero(t, amount) require.Equal( @@ -336,7 +336,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 10, amount = 0.01, nonce = 1, rank = 10 // output: [0.00002, 0.01], 0.01002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 10, 1, 10, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 0.01002, amount) require.Equal(t, ob.utxos[0:2], result) require.Equal(t, uint16(0), clsdtUtxo) @@ -350,7 +350,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 9, amount = 0.01, nonce = 1, rank = 9 // output: [0.00002, 0.01, 0.12], 0.13002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 9, 1, 9, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 0.13002, amount) require.Equal(t, ob.utxos[0:3], result) require.Equal(t, uint16(1), clsdtUtxo) @@ -364,7 +364,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 5, amount = 0.01, nonce = 0, rank = 5 // output: [0.00002, 0.014, 1.26, 0.5, 0.2], 2.01002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 5, 1, 5, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 2.01002, amount) expected := make([]btcjson.ListUnspentResult, 2) copy(expected, ob.utxos[0:2]) @@ -383,7 +383,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 12, amount = 0.01, nonce = 0, rank = 1 // output: [0.00002, 0.01, 8.72, 5.16, 3.28, 2.97, 1.26, 0.5, 0.24, 0.18, 0.12], 22.44002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 12, 1, 1, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 22.44002, amount) expected := make([]btcjson.ListUnspentResult, 2) copy(expected, ob.utxos[0:2]) @@ -407,7 +407,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 5, amount = 0.13, nonce = 24105432, rank = 5 // output: [0.24107431, 0.01, 0.12, 1.26, 0.5, 0.24], 2.37107431 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.13, 5, 24105432, 5, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 2.37107431, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:2]...) expected = append(expected, ob.utxos[6]) @@ -430,7 +430,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 12, amount = 0.13, nonce = 24105432, rank = 1 // output: [0.24107431, 0.01, 0.12, 8.72, 5.16, 3.28, 2.97, 1.26, 0.5, 0.24, 0.18], 22.68107431 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.13, 12, 24105432, 1, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 22.68107431, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:2]...) for i := 10; i >= 5; i-- { // append consolidated utxos in descending order diff --git a/zetaclient/chains/bitcoin/signer/signer_test.go b/zetaclient/chains/bitcoin/signer/signer_test.go index 76b46aef37..6d048c7bba 100644 --- a/zetaclient/chains/bitcoin/signer/signer_test.go +++ b/zetaclient/chains/bitcoin/signer/signer_test.go @@ -370,7 +370,7 @@ func TestAddWithdrawTxOutputs(t *testing.T) { if tt.fail { require.Error(t, err) if tt.message != "" { - require.Contains(t, err.Error(), tt.message) + require.ErrorContains(t, err, tt.message) } return } else { diff --git a/zetaclient/chains/evm/validation_test.go b/zetaclient/chains/evm/validation_test.go index 330d15f8f8..8077f8ab4e 100644 --- a/zetaclient/chains/evm/validation_test.go +++ b/zetaclient/chains/evm/validation_test.go @@ -296,7 +296,7 @@ func TestCheckEvmTransactionTable(t *testing.T) { err := evm.ValidateEvmTransaction(tt.tx) if tt.fail { require.Error(t, err) - require.Contains(t, err.Error(), tt.msg) + require.ErrorContains(t, err, tt.msg) return } require.NoError(t, err) From f4366ad1d3ac7ddf1dadf3eb113198d3bf43ce0e Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Mon, 3 Jun 2024 18:54:05 +0200 Subject: [PATCH 3/6] test(`e2e`): add a test to deploy contracts (#2299) * deploy e2e test * add deploy e2e test to list * make generate * changelog --- changelog.md | 1 + e2e/e2etests/e2etests.go | 17 ++++++ e2e/e2etests/test_deploy_contract.go | 90 ++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 e2e/e2etests/test_deploy_contract.go diff --git a/changelog.md b/changelog.md index cc502322d4..f0f94999ef 100644 --- a/changelog.md +++ b/changelog.md @@ -48,6 +48,7 @@ * [2199](https://github.com/zeta-chain/node/pull/2199) - custom priority mempool unit tests * [2240](https://github.com/zeta-chain/node/pull/2240) - removed hard-coded Bitcoin regnet chainID in E2E withdraw tests * [2266](https://github.com/zeta-chain/node/pull/2266) - try fixing E2E test `crosschain_swap` failure `btc transaction not signed` +* [2299](https://github.com/zeta-chain/node/pull/2299) - add `zetae2e` command to deploy test contracts ### Fixes diff --git a/e2e/e2etests/e2etests.go b/e2e/e2etests/e2etests.go index 83bc455502..348a2a7ef1 100644 --- a/e2e/e2etests/e2etests.go +++ b/e2e/e2etests/e2etests.go @@ -98,6 +98,12 @@ const ( TestUpdateBytecodeZRC20Name = "update_bytecode_zrc20" TestUpdateBytecodeConnectorName = "update_bytecode_connector" TestRateLimiterName = "rate_limiter" + + /* + Special tests + Not used to test functionalities but do various interactions with the netwoks + */ + TestDeploy = "deploy" ) // AllE2ETests is an ordered list of all e2e tests @@ -507,4 +513,15 @@ var AllE2ETests = []runner.E2ETest{ []runner.ArgDefinition{}, TestRateLimiter, ), + /* + Special tests + */ + runner.NewE2ETest( + TestDeploy, + "deploy a contract", + []runner.ArgDefinition{ + {Description: "contract name", DefaultValue: ""}, + }, + TestDeployContract, + ), } diff --git a/e2e/e2etests/test_deploy_contract.go b/e2e/e2etests/test_deploy_contract.go new file mode 100644 index 0000000000..860ae2e0dc --- /dev/null +++ b/e2e/e2etests/test_deploy_contract.go @@ -0,0 +1,90 @@ +package e2etests + +import ( + "fmt" + + ethcommon "github.com/ethereum/go-ethereum/common" + + "github.com/zeta-chain/zetacore/e2e/contracts/testdapp" + "github.com/zeta-chain/zetacore/e2e/runner" + "github.com/zeta-chain/zetacore/e2e/utils" +) + +// deployFunc is a function that deploys a contract +type deployFunc func(r *runner.E2ERunner) (ethcommon.Address, error) + +// deployMap maps contract names to deploy functions +var deployMap = map[string]deployFunc{ + "testdapp_zevm": deployZEVMTestDApp, + "testdapp_evm": deployEVMTestDApp, +} + +// TestDeployContract deploys the specified contract +func TestDeployContract(r *runner.E2ERunner, args []string) { + availableContractNames := make([]string, 0, len(deployMap)) + for contractName := range deployMap { + availableContractNames = append(availableContractNames, contractName) + } + availableContractNamesMessage := fmt.Sprintf("Available contract names: %v", availableContractNames) + + if len(args) != 1 { + panic( + "TestDeployContract requires exactly one argument for the contract name. " + availableContractNamesMessage, + ) + } + contractName := args[0] + + deployFunc, ok := deployMap[contractName] + if !ok { + panic(fmt.Sprintf("Unknown contract name: %s, %s", contractName, availableContractNamesMessage)) + } + + addr, err := deployFunc(r) + if err != nil { + panic(err) + } + + r.Logger.Print("%s deployed at %s", contractName, addr.Hex()) +} + +// deployZEVMTestDApp deploys the TestDApp contract on ZetaChain +func deployZEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) { + addr, tx, _, err := testdapp.DeployTestDApp( + r.ZEVMAuth, + r.ZEVMClient, + r.ConnectorZEVMAddr, + r.WZetaAddr, + ) + if err != nil { + return addr, err + } + + // Wait for the transaction to be mined + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + if receipt.Status != 1 { + return addr, fmt.Errorf("contract deployment failed") + } + + return addr, nil +} + +// deployEVMTestDApp deploys the TestDApp contract on Ethereum +func deployEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) { + addr, tx, _, err := testdapp.DeployTestDApp( + r.EVMAuth, + r.EVMClient, + r.ConnectorEthAddr, + r.ZetaEthAddr, + ) + if err != nil { + return addr, err + } + + // Wait for the transaction to be mined + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + if receipt.Status != 1 { + return addr, fmt.Errorf("contract deployment failed") + } + + return addr, nil +} From 6c8e5a6e09d1b013af21a6dfea6314b82d1079d5 Mon Sep 17 00:00:00 2001 From: Jason Mok <106209849+jasonmokk@users.noreply.github.com> Date: Tue, 4 Jun 2024 03:48:50 -0500 Subject: [PATCH 4/6] refactor: move `testdata` from `pkg` to `testutil` (#2296) * chore: move testdata from pkg to testutil * fix imports * Add changelog entry * Fix pathname in headers_test --------- Co-authored-by: Lucas Bertrand --- changelog.md | 1 + pkg/proofs/bitcoin/proof_test.go | 2 +- pkg/proofs/ethereum/proof_test.go | 2 +- pkg/proofs/headers_test.go | 6 +++--- pkg/proofs/proof_test.go | 2 +- testutil/sample/lightclient.go | 2 +- {pkg => testutil}/testdata/eth_header_18495266.json | 0 {pkg => testutil}/testdata/ethereum/header.json | 0 {pkg => testutil}/testdata/ethereum/receipt_0.json | 0 {pkg => testutil}/testdata/ethereum/receipt_1.json | 0 {pkg => testutil}/testdata/ethereum/receipt_10.json | 0 {pkg => testutil}/testdata/ethereum/receipt_11.json | 0 {pkg => testutil}/testdata/ethereum/receipt_12.json | 0 {pkg => testutil}/testdata/ethereum/receipt_13.json | 0 {pkg => testutil}/testdata/ethereum/receipt_14.json | 0 {pkg => testutil}/testdata/ethereum/receipt_15.json | 0 {pkg => testutil}/testdata/ethereum/receipt_16.json | 0 {pkg => testutil}/testdata/ethereum/receipt_17.json | 0 {pkg => testutil}/testdata/ethereum/receipt_18.json | 0 {pkg => testutil}/testdata/ethereum/receipt_19.json | 0 {pkg => testutil}/testdata/ethereum/receipt_2.json | 0 {pkg => testutil}/testdata/ethereum/receipt_20.json | 0 {pkg => testutil}/testdata/ethereum/receipt_21.json | 0 {pkg => testutil}/testdata/ethereum/receipt_22.json | 0 {pkg => testutil}/testdata/ethereum/receipt_23.json | 0 {pkg => testutil}/testdata/ethereum/receipt_24.json | 0 {pkg => testutil}/testdata/ethereum/receipt_25.json | 0 {pkg => testutil}/testdata/ethereum/receipt_26.json | 0 {pkg => testutil}/testdata/ethereum/receipt_27.json | 0 {pkg => testutil}/testdata/ethereum/receipt_28.json | 0 {pkg => testutil}/testdata/ethereum/receipt_29.json | 0 {pkg => testutil}/testdata/ethereum/receipt_3.json | 0 {pkg => testutil}/testdata/ethereum/receipt_30.json | 0 {pkg => testutil}/testdata/ethereum/receipt_31.json | 0 {pkg => testutil}/testdata/ethereum/receipt_32.json | 0 {pkg => testutil}/testdata/ethereum/receipt_33.json | 0 {pkg => testutil}/testdata/ethereum/receipt_34.json | 0 {pkg => testutil}/testdata/ethereum/receipt_35.json | 0 {pkg => testutil}/testdata/ethereum/receipt_36.json | 0 {pkg => testutil}/testdata/ethereum/receipt_37.json | 0 {pkg => testutil}/testdata/ethereum/receipt_38.json | 0 {pkg => testutil}/testdata/ethereum/receipt_39.json | 0 {pkg => testutil}/testdata/ethereum/receipt_4.json | 0 {pkg => testutil}/testdata/ethereum/receipt_40.json | 0 {pkg => testutil}/testdata/ethereum/receipt_41.json | 0 {pkg => testutil}/testdata/ethereum/receipt_42.json | 0 {pkg => testutil}/testdata/ethereum/receipt_43.json | 0 {pkg => testutil}/testdata/ethereum/receipt_44.json | 0 {pkg => testutil}/testdata/ethereum/receipt_45.json | 0 {pkg => testutil}/testdata/ethereum/receipt_46.json | 0 {pkg => testutil}/testdata/ethereum/receipt_47.json | 0 {pkg => testutil}/testdata/ethereum/receipt_48.json | 0 {pkg => testutil}/testdata/ethereum/receipt_49.json | 0 {pkg => testutil}/testdata/ethereum/receipt_5.json | 0 {pkg => testutil}/testdata/ethereum/receipt_50.json | 0 {pkg => testutil}/testdata/ethereum/receipt_51.json | 0 {pkg => testutil}/testdata/ethereum/receipt_52.json | 0 {pkg => testutil}/testdata/ethereum/receipt_53.json | 0 {pkg => testutil}/testdata/ethereum/receipt_54.json | 0 {pkg => testutil}/testdata/ethereum/receipt_55.json | 0 {pkg => testutil}/testdata/ethereum/receipt_56.json | 0 {pkg => testutil}/testdata/ethereum/receipt_57.json | 0 {pkg => testutil}/testdata/ethereum/receipt_58.json | 0 {pkg => testutil}/testdata/ethereum/receipt_59.json | 0 {pkg => testutil}/testdata/ethereum/receipt_6.json | 0 {pkg => testutil}/testdata/ethereum/receipt_60.json | 0 {pkg => testutil}/testdata/ethereum/receipt_61.json | 0 {pkg => testutil}/testdata/ethereum/receipt_62.json | 0 {pkg => testutil}/testdata/ethereum/receipt_63.json | 0 {pkg => testutil}/testdata/ethereum/receipt_64.json | 0 {pkg => testutil}/testdata/ethereum/receipt_65.json | 0 {pkg => testutil}/testdata/ethereum/receipt_66.json | 0 {pkg => testutil}/testdata/ethereum/receipt_67.json | 0 {pkg => testutil}/testdata/ethereum/receipt_68.json | 0 {pkg => testutil}/testdata/ethereum/receipt_69.json | 0 {pkg => testutil}/testdata/ethereum/receipt_7.json | 0 {pkg => testutil}/testdata/ethereum/receipt_70.json | 0 {pkg => testutil}/testdata/ethereum/receipt_71.json | 0 {pkg => testutil}/testdata/ethereum/receipt_72.json | 0 {pkg => testutil}/testdata/ethereum/receipt_73.json | 0 {pkg => testutil}/testdata/ethereum/receipt_74.json | 0 {pkg => testutil}/testdata/ethereum/receipt_75.json | 0 {pkg => testutil}/testdata/ethereum/receipt_76.json | 0 {pkg => testutil}/testdata/ethereum/receipt_77.json | 0 {pkg => testutil}/testdata/ethereum/receipt_78.json | 0 {pkg => testutil}/testdata/ethereum/receipt_79.json | 0 {pkg => testutil}/testdata/ethereum/receipt_8.json | 0 {pkg => testutil}/testdata/ethereum/receipt_80.json | 0 {pkg => testutil}/testdata/ethereum/receipt_9.json | 0 {pkg => testutil}/testdata/ethereum/tx_0.json | 0 {pkg => testutil}/testdata/ethereum/tx_1.json | 0 {pkg => testutil}/testdata/ethereum/tx_10.json | 0 {pkg => testutil}/testdata/ethereum/tx_11.json | 0 {pkg => testutil}/testdata/ethereum/tx_12.json | 0 {pkg => testutil}/testdata/ethereum/tx_13.json | 0 {pkg => testutil}/testdata/ethereum/tx_14.json | 0 {pkg => testutil}/testdata/ethereum/tx_15.json | 0 {pkg => testutil}/testdata/ethereum/tx_16.json | 0 {pkg => testutil}/testdata/ethereum/tx_17.json | 0 {pkg => testutil}/testdata/ethereum/tx_18.json | 0 {pkg => testutil}/testdata/ethereum/tx_19.json | 0 {pkg => testutil}/testdata/ethereum/tx_2.json | 0 {pkg => testutil}/testdata/ethereum/tx_20.json | 0 {pkg => testutil}/testdata/ethereum/tx_21.json | 0 {pkg => testutil}/testdata/ethereum/tx_22.json | 0 {pkg => testutil}/testdata/ethereum/tx_23.json | 0 {pkg => testutil}/testdata/ethereum/tx_24.json | 0 {pkg => testutil}/testdata/ethereum/tx_25.json | 0 {pkg => testutil}/testdata/ethereum/tx_26.json | 0 {pkg => testutil}/testdata/ethereum/tx_27.json | 0 {pkg => testutil}/testdata/ethereum/tx_28.json | 0 {pkg => testutil}/testdata/ethereum/tx_29.json | 0 {pkg => testutil}/testdata/ethereum/tx_3.json | 0 {pkg => testutil}/testdata/ethereum/tx_30.json | 0 {pkg => testutil}/testdata/ethereum/tx_31.json | 0 {pkg => testutil}/testdata/ethereum/tx_32.json | 0 {pkg => testutil}/testdata/ethereum/tx_33.json | 0 {pkg => testutil}/testdata/ethereum/tx_34.json | 0 {pkg => testutil}/testdata/ethereum/tx_35.json | 0 {pkg => testutil}/testdata/ethereum/tx_36.json | 0 {pkg => testutil}/testdata/ethereum/tx_37.json | 0 {pkg => testutil}/testdata/ethereum/tx_38.json | 0 {pkg => testutil}/testdata/ethereum/tx_39.json | 0 {pkg => testutil}/testdata/ethereum/tx_4.json | 0 {pkg => testutil}/testdata/ethereum/tx_40.json | 0 {pkg => testutil}/testdata/ethereum/tx_41.json | 0 {pkg => testutil}/testdata/ethereum/tx_42.json | 0 {pkg => testutil}/testdata/ethereum/tx_43.json | 0 {pkg => testutil}/testdata/ethereum/tx_44.json | 0 {pkg => testutil}/testdata/ethereum/tx_45.json | 0 {pkg => testutil}/testdata/ethereum/tx_46.json | 0 {pkg => testutil}/testdata/ethereum/tx_47.json | 0 {pkg => testutil}/testdata/ethereum/tx_48.json | 0 {pkg => testutil}/testdata/ethereum/tx_49.json | 0 {pkg => testutil}/testdata/ethereum/tx_5.json | 0 {pkg => testutil}/testdata/ethereum/tx_50.json | 0 {pkg => testutil}/testdata/ethereum/tx_51.json | 0 {pkg => testutil}/testdata/ethereum/tx_52.json | 0 {pkg => testutil}/testdata/ethereum/tx_53.json | 0 {pkg => testutil}/testdata/ethereum/tx_54.json | 0 {pkg => testutil}/testdata/ethereum/tx_55.json | 0 {pkg => testutil}/testdata/ethereum/tx_56.json | 0 {pkg => testutil}/testdata/ethereum/tx_57.json | 0 {pkg => testutil}/testdata/ethereum/tx_58.json | 0 {pkg => testutil}/testdata/ethereum/tx_59.json | 0 {pkg => testutil}/testdata/ethereum/tx_6.json | 0 {pkg => testutil}/testdata/ethereum/tx_60.json | 0 {pkg => testutil}/testdata/ethereum/tx_61.json | 0 {pkg => testutil}/testdata/ethereum/tx_62.json | 0 {pkg => testutil}/testdata/ethereum/tx_63.json | 0 {pkg => testutil}/testdata/ethereum/tx_64.json | 0 {pkg => testutil}/testdata/ethereum/tx_65.json | 0 {pkg => testutil}/testdata/ethereum/tx_66.json | 0 {pkg => testutil}/testdata/ethereum/tx_67.json | 0 {pkg => testutil}/testdata/ethereum/tx_68.json | 0 {pkg => testutil}/testdata/ethereum/tx_69.json | 0 {pkg => testutil}/testdata/ethereum/tx_7.json | 0 {pkg => testutil}/testdata/ethereum/tx_70.json | 0 {pkg => testutil}/testdata/ethereum/tx_71.json | 0 {pkg => testutil}/testdata/ethereum/tx_72.json | 0 {pkg => testutil}/testdata/ethereum/tx_73.json | 0 {pkg => testutil}/testdata/ethereum/tx_74.json | 0 {pkg => testutil}/testdata/ethereum/tx_75.json | 0 {pkg => testutil}/testdata/ethereum/tx_76.json | 0 {pkg => testutil}/testdata/ethereum/tx_77.json | 0 {pkg => testutil}/testdata/ethereum/tx_78.json | 0 {pkg => testutil}/testdata/ethereum/tx_79.json | 0 {pkg => testutil}/testdata/ethereum/tx_8.json | 0 {pkg => testutil}/testdata/ethereum/tx_80.json | 0 {pkg => testutil}/testdata/ethereum/tx_9.json | 0 {pkg => testutil}/testdata/test_blocks.json | 0 {pkg => testutil}/testdata/testdata.go | 0 {pkg => testutil}/testdata/types/chain_info.json | 0 {pkg => testutil}/testdata/types/policies.json | 0 x/authority/client/cli/tx_update_chain_info_test.go | 2 +- x/authority/client/cli/tx_update_policies_test.go | 2 +- x/observer/types/message_vote_block_header_test.go | 2 +- zetaclient/zetacore/tx_test.go | 2 +- 178 files changed, 12 insertions(+), 11 deletions(-) rename {pkg => testutil}/testdata/eth_header_18495266.json (100%) rename {pkg => testutil}/testdata/ethereum/header.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_0.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_1.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_10.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_11.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_12.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_13.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_14.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_15.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_16.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_17.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_18.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_19.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_2.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_20.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_21.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_22.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_23.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_24.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_25.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_26.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_27.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_28.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_29.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_3.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_30.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_31.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_32.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_33.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_34.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_35.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_36.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_37.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_38.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_39.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_4.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_40.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_41.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_42.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_43.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_44.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_45.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_46.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_47.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_48.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_49.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_5.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_50.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_51.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_52.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_53.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_54.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_55.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_56.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_57.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_58.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_59.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_6.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_60.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_61.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_62.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_63.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_64.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_65.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_66.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_67.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_68.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_69.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_7.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_70.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_71.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_72.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_73.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_74.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_75.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_76.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_77.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_78.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_79.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_8.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_80.json (100%) rename {pkg => testutil}/testdata/ethereum/receipt_9.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_0.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_1.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_10.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_11.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_12.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_13.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_14.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_15.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_16.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_17.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_18.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_19.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_2.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_20.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_21.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_22.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_23.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_24.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_25.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_26.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_27.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_28.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_29.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_3.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_30.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_31.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_32.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_33.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_34.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_35.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_36.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_37.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_38.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_39.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_4.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_40.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_41.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_42.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_43.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_44.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_45.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_46.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_47.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_48.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_49.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_5.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_50.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_51.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_52.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_53.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_54.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_55.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_56.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_57.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_58.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_59.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_6.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_60.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_61.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_62.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_63.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_64.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_65.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_66.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_67.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_68.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_69.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_7.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_70.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_71.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_72.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_73.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_74.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_75.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_76.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_77.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_78.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_79.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_8.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_80.json (100%) rename {pkg => testutil}/testdata/ethereum/tx_9.json (100%) rename {pkg => testutil}/testdata/test_blocks.json (100%) rename {pkg => testutil}/testdata/testdata.go (100%) rename {pkg => testutil}/testdata/types/chain_info.json (100%) rename {pkg => testutil}/testdata/types/policies.json (100%) diff --git a/changelog.md b/changelog.md index f0f94999ef..82d90197d2 100644 --- a/changelog.md +++ b/changelog.md @@ -39,6 +39,7 @@ * [2262](https://github.com/zeta-chain/node/pull/2262) - refactor MsgUpdateZRC20 into MsgPauseZrc20 and MsgUnPauseZRC20 * [2290](https://github.com/zeta-chain/node/pull/2290) - rename `MsgAddBlameVote` message to `MsgVoteBlame` * [2269](https://github.com/zeta-chain/node/pull/2269) - refactor MsgUpdateCrosschainFlags into MsgEnableCCTX, MsgDisableCCTX and MsgUpdateGasPriceIncreaseFlags +* [2296](https://github.com/zeta-chain/node/pull/2296) - move `testdata` package to `testutil` to organize test-related utilities ### Tests diff --git a/pkg/proofs/bitcoin/proof_test.go b/pkg/proofs/bitcoin/proof_test.go index 23444e22d6..ad9801f6ce 100644 --- a/pkg/proofs/bitcoin/proof_test.go +++ b/pkg/proofs/bitcoin/proof_test.go @@ -13,7 +13,7 @@ import ( "github.com/btcsuite/btcutil" "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/testdata" + "github.com/zeta-chain/zetacore/testutil/testdata" ) func TestBitcoinMerkleProof(t *testing.T) { diff --git a/pkg/proofs/ethereum/proof_test.go b/pkg/proofs/ethereum/proof_test.go index b6c676b0ee..8fb67c591b 100644 --- a/pkg/proofs/ethereum/proof_test.go +++ b/pkg/proofs/ethereum/proof_test.go @@ -6,7 +6,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/testdata" + "github.com/zeta-chain/zetacore/testutil/testdata" ) func TestProofGeneration(t *testing.T) { diff --git a/pkg/proofs/headers_test.go b/pkg/proofs/headers_test.go index 5d992a4686..8125435878 100644 --- a/pkg/proofs/headers_test.go +++ b/pkg/proofs/headers_test.go @@ -17,7 +17,7 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/testdata" + "github.com/zeta-chain/zetacore/testutil/testdata" ) const numHeadersToTest = 100 @@ -25,7 +25,7 @@ const numHeadersToTest = 100 func TestTrueEthereumHeader(t *testing.T) { var header ethtypes.Header // read file into a byte slice - file, err := os.Open("../testdata/eth_header_18495266.json") + file, err := os.Open("../../testutil/testdata/eth_header_18495266.json") require.NoError(t, err) defer file.Close() headerBytes := make([]byte, 4096) @@ -52,7 +52,7 @@ func TestTrueEthereumHeader(t *testing.T) { func TestFalseEthereumHeader(t *testing.T) { var header ethtypes.Header // read file into a byte slice - file, err := os.Open("../testdata/eth_header_18495266.json") + file, err := os.Open("../../testutil/testdata/eth_header_18495266.json") require.NoError(t, err) defer file.Close() headerBytes := make([]byte, 4096) diff --git a/pkg/proofs/proof_test.go b/pkg/proofs/proof_test.go index b9210e9260..7be25350f4 100644 --- a/pkg/proofs/proof_test.go +++ b/pkg/proofs/proof_test.go @@ -18,7 +18,7 @@ import ( "github.com/zeta-chain/zetacore/pkg/proofs/bitcoin" "github.com/zeta-chain/zetacore/pkg/proofs/ethereum" - "github.com/zeta-chain/zetacore/pkg/testdata" + "github.com/zeta-chain/zetacore/testutil/testdata" ) const ( diff --git a/testutil/sample/lightclient.go b/testutil/sample/lightclient.go index 1d3725876a..70aa55b51a 100644 --- a/testutil/sample/lightclient.go +++ b/testutil/sample/lightclient.go @@ -11,7 +11,7 @@ import ( "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/pkg/proofs/ethereum" - "github.com/zeta-chain/zetacore/pkg/testdata" + "github.com/zeta-chain/zetacore/testutil/testdata" lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" ) diff --git a/pkg/testdata/eth_header_18495266.json b/testutil/testdata/eth_header_18495266.json similarity index 100% rename from pkg/testdata/eth_header_18495266.json rename to testutil/testdata/eth_header_18495266.json diff --git a/pkg/testdata/ethereum/header.json b/testutil/testdata/ethereum/header.json similarity index 100% rename from pkg/testdata/ethereum/header.json rename to testutil/testdata/ethereum/header.json diff --git a/pkg/testdata/ethereum/receipt_0.json b/testutil/testdata/ethereum/receipt_0.json similarity index 100% rename from pkg/testdata/ethereum/receipt_0.json rename to testutil/testdata/ethereum/receipt_0.json diff --git a/pkg/testdata/ethereum/receipt_1.json b/testutil/testdata/ethereum/receipt_1.json similarity index 100% rename from pkg/testdata/ethereum/receipt_1.json rename to testutil/testdata/ethereum/receipt_1.json diff --git a/pkg/testdata/ethereum/receipt_10.json b/testutil/testdata/ethereum/receipt_10.json similarity index 100% rename from pkg/testdata/ethereum/receipt_10.json rename to testutil/testdata/ethereum/receipt_10.json diff --git a/pkg/testdata/ethereum/receipt_11.json b/testutil/testdata/ethereum/receipt_11.json similarity index 100% rename from pkg/testdata/ethereum/receipt_11.json rename to testutil/testdata/ethereum/receipt_11.json diff --git a/pkg/testdata/ethereum/receipt_12.json b/testutil/testdata/ethereum/receipt_12.json similarity index 100% rename from pkg/testdata/ethereum/receipt_12.json rename to testutil/testdata/ethereum/receipt_12.json diff --git a/pkg/testdata/ethereum/receipt_13.json b/testutil/testdata/ethereum/receipt_13.json similarity index 100% rename from pkg/testdata/ethereum/receipt_13.json rename to testutil/testdata/ethereum/receipt_13.json diff --git a/pkg/testdata/ethereum/receipt_14.json b/testutil/testdata/ethereum/receipt_14.json similarity index 100% rename from pkg/testdata/ethereum/receipt_14.json rename to testutil/testdata/ethereum/receipt_14.json diff --git a/pkg/testdata/ethereum/receipt_15.json b/testutil/testdata/ethereum/receipt_15.json similarity index 100% rename from pkg/testdata/ethereum/receipt_15.json rename to testutil/testdata/ethereum/receipt_15.json diff --git a/pkg/testdata/ethereum/receipt_16.json b/testutil/testdata/ethereum/receipt_16.json similarity index 100% rename from pkg/testdata/ethereum/receipt_16.json rename to testutil/testdata/ethereum/receipt_16.json diff --git a/pkg/testdata/ethereum/receipt_17.json b/testutil/testdata/ethereum/receipt_17.json similarity index 100% rename from pkg/testdata/ethereum/receipt_17.json rename to testutil/testdata/ethereum/receipt_17.json diff --git a/pkg/testdata/ethereum/receipt_18.json b/testutil/testdata/ethereum/receipt_18.json similarity index 100% rename from pkg/testdata/ethereum/receipt_18.json rename to testutil/testdata/ethereum/receipt_18.json diff --git a/pkg/testdata/ethereum/receipt_19.json b/testutil/testdata/ethereum/receipt_19.json similarity index 100% rename from pkg/testdata/ethereum/receipt_19.json rename to testutil/testdata/ethereum/receipt_19.json diff --git a/pkg/testdata/ethereum/receipt_2.json b/testutil/testdata/ethereum/receipt_2.json similarity index 100% rename from pkg/testdata/ethereum/receipt_2.json rename to testutil/testdata/ethereum/receipt_2.json diff --git a/pkg/testdata/ethereum/receipt_20.json b/testutil/testdata/ethereum/receipt_20.json similarity index 100% rename from pkg/testdata/ethereum/receipt_20.json rename to testutil/testdata/ethereum/receipt_20.json diff --git a/pkg/testdata/ethereum/receipt_21.json b/testutil/testdata/ethereum/receipt_21.json similarity index 100% rename from pkg/testdata/ethereum/receipt_21.json rename to testutil/testdata/ethereum/receipt_21.json diff --git a/pkg/testdata/ethereum/receipt_22.json b/testutil/testdata/ethereum/receipt_22.json similarity index 100% rename from pkg/testdata/ethereum/receipt_22.json rename to testutil/testdata/ethereum/receipt_22.json diff --git a/pkg/testdata/ethereum/receipt_23.json b/testutil/testdata/ethereum/receipt_23.json similarity index 100% rename from pkg/testdata/ethereum/receipt_23.json rename to testutil/testdata/ethereum/receipt_23.json diff --git a/pkg/testdata/ethereum/receipt_24.json b/testutil/testdata/ethereum/receipt_24.json similarity index 100% rename from pkg/testdata/ethereum/receipt_24.json rename to testutil/testdata/ethereum/receipt_24.json diff --git a/pkg/testdata/ethereum/receipt_25.json b/testutil/testdata/ethereum/receipt_25.json similarity index 100% rename from pkg/testdata/ethereum/receipt_25.json rename to testutil/testdata/ethereum/receipt_25.json diff --git a/pkg/testdata/ethereum/receipt_26.json b/testutil/testdata/ethereum/receipt_26.json similarity index 100% rename from pkg/testdata/ethereum/receipt_26.json rename to testutil/testdata/ethereum/receipt_26.json diff --git a/pkg/testdata/ethereum/receipt_27.json b/testutil/testdata/ethereum/receipt_27.json similarity index 100% rename from pkg/testdata/ethereum/receipt_27.json rename to testutil/testdata/ethereum/receipt_27.json diff --git a/pkg/testdata/ethereum/receipt_28.json b/testutil/testdata/ethereum/receipt_28.json similarity index 100% rename from pkg/testdata/ethereum/receipt_28.json rename to testutil/testdata/ethereum/receipt_28.json diff --git a/pkg/testdata/ethereum/receipt_29.json b/testutil/testdata/ethereum/receipt_29.json similarity index 100% rename from pkg/testdata/ethereum/receipt_29.json rename to testutil/testdata/ethereum/receipt_29.json diff --git a/pkg/testdata/ethereum/receipt_3.json b/testutil/testdata/ethereum/receipt_3.json similarity index 100% rename from pkg/testdata/ethereum/receipt_3.json rename to testutil/testdata/ethereum/receipt_3.json diff --git a/pkg/testdata/ethereum/receipt_30.json b/testutil/testdata/ethereum/receipt_30.json similarity index 100% rename from pkg/testdata/ethereum/receipt_30.json rename to testutil/testdata/ethereum/receipt_30.json diff --git a/pkg/testdata/ethereum/receipt_31.json b/testutil/testdata/ethereum/receipt_31.json similarity index 100% rename from pkg/testdata/ethereum/receipt_31.json rename to testutil/testdata/ethereum/receipt_31.json diff --git a/pkg/testdata/ethereum/receipt_32.json b/testutil/testdata/ethereum/receipt_32.json similarity index 100% rename from pkg/testdata/ethereum/receipt_32.json rename to testutil/testdata/ethereum/receipt_32.json diff --git a/pkg/testdata/ethereum/receipt_33.json b/testutil/testdata/ethereum/receipt_33.json similarity index 100% rename from pkg/testdata/ethereum/receipt_33.json rename to testutil/testdata/ethereum/receipt_33.json diff --git a/pkg/testdata/ethereum/receipt_34.json b/testutil/testdata/ethereum/receipt_34.json similarity index 100% rename from pkg/testdata/ethereum/receipt_34.json rename to testutil/testdata/ethereum/receipt_34.json diff --git a/pkg/testdata/ethereum/receipt_35.json b/testutil/testdata/ethereum/receipt_35.json similarity index 100% rename from pkg/testdata/ethereum/receipt_35.json rename to testutil/testdata/ethereum/receipt_35.json diff --git a/pkg/testdata/ethereum/receipt_36.json b/testutil/testdata/ethereum/receipt_36.json similarity index 100% rename from pkg/testdata/ethereum/receipt_36.json rename to testutil/testdata/ethereum/receipt_36.json diff --git a/pkg/testdata/ethereum/receipt_37.json b/testutil/testdata/ethereum/receipt_37.json similarity index 100% rename from pkg/testdata/ethereum/receipt_37.json rename to testutil/testdata/ethereum/receipt_37.json diff --git a/pkg/testdata/ethereum/receipt_38.json b/testutil/testdata/ethereum/receipt_38.json similarity index 100% rename from pkg/testdata/ethereum/receipt_38.json rename to testutil/testdata/ethereum/receipt_38.json diff --git a/pkg/testdata/ethereum/receipt_39.json b/testutil/testdata/ethereum/receipt_39.json similarity index 100% rename from pkg/testdata/ethereum/receipt_39.json rename to testutil/testdata/ethereum/receipt_39.json diff --git a/pkg/testdata/ethereum/receipt_4.json b/testutil/testdata/ethereum/receipt_4.json similarity index 100% rename from pkg/testdata/ethereum/receipt_4.json rename to testutil/testdata/ethereum/receipt_4.json diff --git a/pkg/testdata/ethereum/receipt_40.json b/testutil/testdata/ethereum/receipt_40.json similarity index 100% rename from pkg/testdata/ethereum/receipt_40.json rename to testutil/testdata/ethereum/receipt_40.json diff --git a/pkg/testdata/ethereum/receipt_41.json b/testutil/testdata/ethereum/receipt_41.json similarity index 100% rename from pkg/testdata/ethereum/receipt_41.json rename to testutil/testdata/ethereum/receipt_41.json diff --git a/pkg/testdata/ethereum/receipt_42.json b/testutil/testdata/ethereum/receipt_42.json similarity index 100% rename from pkg/testdata/ethereum/receipt_42.json rename to testutil/testdata/ethereum/receipt_42.json diff --git a/pkg/testdata/ethereum/receipt_43.json b/testutil/testdata/ethereum/receipt_43.json similarity index 100% rename from pkg/testdata/ethereum/receipt_43.json rename to testutil/testdata/ethereum/receipt_43.json diff --git a/pkg/testdata/ethereum/receipt_44.json b/testutil/testdata/ethereum/receipt_44.json similarity index 100% rename from pkg/testdata/ethereum/receipt_44.json rename to testutil/testdata/ethereum/receipt_44.json diff --git a/pkg/testdata/ethereum/receipt_45.json b/testutil/testdata/ethereum/receipt_45.json similarity index 100% rename from pkg/testdata/ethereum/receipt_45.json rename to testutil/testdata/ethereum/receipt_45.json diff --git a/pkg/testdata/ethereum/receipt_46.json b/testutil/testdata/ethereum/receipt_46.json similarity index 100% rename from pkg/testdata/ethereum/receipt_46.json rename to testutil/testdata/ethereum/receipt_46.json diff --git a/pkg/testdata/ethereum/receipt_47.json b/testutil/testdata/ethereum/receipt_47.json similarity index 100% rename from pkg/testdata/ethereum/receipt_47.json rename to testutil/testdata/ethereum/receipt_47.json diff --git a/pkg/testdata/ethereum/receipt_48.json b/testutil/testdata/ethereum/receipt_48.json similarity index 100% rename from pkg/testdata/ethereum/receipt_48.json rename to testutil/testdata/ethereum/receipt_48.json diff --git a/pkg/testdata/ethereum/receipt_49.json b/testutil/testdata/ethereum/receipt_49.json similarity index 100% rename from pkg/testdata/ethereum/receipt_49.json rename to testutil/testdata/ethereum/receipt_49.json diff --git a/pkg/testdata/ethereum/receipt_5.json b/testutil/testdata/ethereum/receipt_5.json similarity index 100% rename from pkg/testdata/ethereum/receipt_5.json rename to testutil/testdata/ethereum/receipt_5.json diff --git a/pkg/testdata/ethereum/receipt_50.json b/testutil/testdata/ethereum/receipt_50.json similarity index 100% rename from pkg/testdata/ethereum/receipt_50.json rename to testutil/testdata/ethereum/receipt_50.json diff --git a/pkg/testdata/ethereum/receipt_51.json b/testutil/testdata/ethereum/receipt_51.json similarity index 100% rename from pkg/testdata/ethereum/receipt_51.json rename to testutil/testdata/ethereum/receipt_51.json diff --git a/pkg/testdata/ethereum/receipt_52.json b/testutil/testdata/ethereum/receipt_52.json similarity index 100% rename from pkg/testdata/ethereum/receipt_52.json rename to testutil/testdata/ethereum/receipt_52.json diff --git a/pkg/testdata/ethereum/receipt_53.json b/testutil/testdata/ethereum/receipt_53.json similarity index 100% rename from pkg/testdata/ethereum/receipt_53.json rename to testutil/testdata/ethereum/receipt_53.json diff --git a/pkg/testdata/ethereum/receipt_54.json b/testutil/testdata/ethereum/receipt_54.json similarity index 100% rename from pkg/testdata/ethereum/receipt_54.json rename to testutil/testdata/ethereum/receipt_54.json diff --git a/pkg/testdata/ethereum/receipt_55.json b/testutil/testdata/ethereum/receipt_55.json similarity index 100% rename from pkg/testdata/ethereum/receipt_55.json rename to testutil/testdata/ethereum/receipt_55.json diff --git a/pkg/testdata/ethereum/receipt_56.json b/testutil/testdata/ethereum/receipt_56.json similarity index 100% rename from pkg/testdata/ethereum/receipt_56.json rename to testutil/testdata/ethereum/receipt_56.json diff --git a/pkg/testdata/ethereum/receipt_57.json b/testutil/testdata/ethereum/receipt_57.json similarity index 100% rename from pkg/testdata/ethereum/receipt_57.json rename to testutil/testdata/ethereum/receipt_57.json diff --git a/pkg/testdata/ethereum/receipt_58.json b/testutil/testdata/ethereum/receipt_58.json similarity index 100% rename from pkg/testdata/ethereum/receipt_58.json rename to testutil/testdata/ethereum/receipt_58.json diff --git a/pkg/testdata/ethereum/receipt_59.json b/testutil/testdata/ethereum/receipt_59.json similarity index 100% rename from pkg/testdata/ethereum/receipt_59.json rename to testutil/testdata/ethereum/receipt_59.json diff --git a/pkg/testdata/ethereum/receipt_6.json b/testutil/testdata/ethereum/receipt_6.json similarity index 100% rename from pkg/testdata/ethereum/receipt_6.json rename to testutil/testdata/ethereum/receipt_6.json diff --git a/pkg/testdata/ethereum/receipt_60.json b/testutil/testdata/ethereum/receipt_60.json similarity index 100% rename from pkg/testdata/ethereum/receipt_60.json rename to testutil/testdata/ethereum/receipt_60.json diff --git a/pkg/testdata/ethereum/receipt_61.json b/testutil/testdata/ethereum/receipt_61.json similarity index 100% rename from pkg/testdata/ethereum/receipt_61.json rename to testutil/testdata/ethereum/receipt_61.json diff --git a/pkg/testdata/ethereum/receipt_62.json b/testutil/testdata/ethereum/receipt_62.json similarity index 100% rename from pkg/testdata/ethereum/receipt_62.json rename to testutil/testdata/ethereum/receipt_62.json diff --git a/pkg/testdata/ethereum/receipt_63.json b/testutil/testdata/ethereum/receipt_63.json similarity index 100% rename from pkg/testdata/ethereum/receipt_63.json rename to testutil/testdata/ethereum/receipt_63.json diff --git a/pkg/testdata/ethereum/receipt_64.json b/testutil/testdata/ethereum/receipt_64.json similarity index 100% rename from pkg/testdata/ethereum/receipt_64.json rename to testutil/testdata/ethereum/receipt_64.json diff --git a/pkg/testdata/ethereum/receipt_65.json b/testutil/testdata/ethereum/receipt_65.json similarity index 100% rename from pkg/testdata/ethereum/receipt_65.json rename to testutil/testdata/ethereum/receipt_65.json diff --git a/pkg/testdata/ethereum/receipt_66.json b/testutil/testdata/ethereum/receipt_66.json similarity index 100% rename from pkg/testdata/ethereum/receipt_66.json rename to testutil/testdata/ethereum/receipt_66.json diff --git a/pkg/testdata/ethereum/receipt_67.json b/testutil/testdata/ethereum/receipt_67.json similarity index 100% rename from pkg/testdata/ethereum/receipt_67.json rename to testutil/testdata/ethereum/receipt_67.json diff --git a/pkg/testdata/ethereum/receipt_68.json b/testutil/testdata/ethereum/receipt_68.json similarity index 100% rename from pkg/testdata/ethereum/receipt_68.json rename to testutil/testdata/ethereum/receipt_68.json diff --git a/pkg/testdata/ethereum/receipt_69.json b/testutil/testdata/ethereum/receipt_69.json similarity index 100% rename from pkg/testdata/ethereum/receipt_69.json rename to testutil/testdata/ethereum/receipt_69.json diff --git a/pkg/testdata/ethereum/receipt_7.json b/testutil/testdata/ethereum/receipt_7.json similarity index 100% rename from pkg/testdata/ethereum/receipt_7.json rename to testutil/testdata/ethereum/receipt_7.json diff --git a/pkg/testdata/ethereum/receipt_70.json b/testutil/testdata/ethereum/receipt_70.json similarity index 100% rename from pkg/testdata/ethereum/receipt_70.json rename to testutil/testdata/ethereum/receipt_70.json diff --git a/pkg/testdata/ethereum/receipt_71.json b/testutil/testdata/ethereum/receipt_71.json similarity index 100% rename from pkg/testdata/ethereum/receipt_71.json rename to testutil/testdata/ethereum/receipt_71.json diff --git a/pkg/testdata/ethereum/receipt_72.json b/testutil/testdata/ethereum/receipt_72.json similarity index 100% rename from pkg/testdata/ethereum/receipt_72.json rename to testutil/testdata/ethereum/receipt_72.json diff --git a/pkg/testdata/ethereum/receipt_73.json b/testutil/testdata/ethereum/receipt_73.json similarity index 100% rename from pkg/testdata/ethereum/receipt_73.json rename to testutil/testdata/ethereum/receipt_73.json diff --git a/pkg/testdata/ethereum/receipt_74.json b/testutil/testdata/ethereum/receipt_74.json similarity index 100% rename from pkg/testdata/ethereum/receipt_74.json rename to testutil/testdata/ethereum/receipt_74.json diff --git a/pkg/testdata/ethereum/receipt_75.json b/testutil/testdata/ethereum/receipt_75.json similarity index 100% rename from pkg/testdata/ethereum/receipt_75.json rename to testutil/testdata/ethereum/receipt_75.json diff --git a/pkg/testdata/ethereum/receipt_76.json b/testutil/testdata/ethereum/receipt_76.json similarity index 100% rename from pkg/testdata/ethereum/receipt_76.json rename to testutil/testdata/ethereum/receipt_76.json diff --git a/pkg/testdata/ethereum/receipt_77.json b/testutil/testdata/ethereum/receipt_77.json similarity index 100% rename from pkg/testdata/ethereum/receipt_77.json rename to testutil/testdata/ethereum/receipt_77.json diff --git a/pkg/testdata/ethereum/receipt_78.json b/testutil/testdata/ethereum/receipt_78.json similarity index 100% rename from pkg/testdata/ethereum/receipt_78.json rename to testutil/testdata/ethereum/receipt_78.json diff --git a/pkg/testdata/ethereum/receipt_79.json b/testutil/testdata/ethereum/receipt_79.json similarity index 100% rename from pkg/testdata/ethereum/receipt_79.json rename to testutil/testdata/ethereum/receipt_79.json diff --git a/pkg/testdata/ethereum/receipt_8.json b/testutil/testdata/ethereum/receipt_8.json similarity index 100% rename from pkg/testdata/ethereum/receipt_8.json rename to testutil/testdata/ethereum/receipt_8.json diff --git a/pkg/testdata/ethereum/receipt_80.json b/testutil/testdata/ethereum/receipt_80.json similarity index 100% rename from pkg/testdata/ethereum/receipt_80.json rename to testutil/testdata/ethereum/receipt_80.json diff --git a/pkg/testdata/ethereum/receipt_9.json b/testutil/testdata/ethereum/receipt_9.json similarity index 100% rename from pkg/testdata/ethereum/receipt_9.json rename to testutil/testdata/ethereum/receipt_9.json diff --git a/pkg/testdata/ethereum/tx_0.json b/testutil/testdata/ethereum/tx_0.json similarity index 100% rename from pkg/testdata/ethereum/tx_0.json rename to testutil/testdata/ethereum/tx_0.json diff --git a/pkg/testdata/ethereum/tx_1.json b/testutil/testdata/ethereum/tx_1.json similarity index 100% rename from pkg/testdata/ethereum/tx_1.json rename to testutil/testdata/ethereum/tx_1.json diff --git a/pkg/testdata/ethereum/tx_10.json b/testutil/testdata/ethereum/tx_10.json similarity index 100% rename from pkg/testdata/ethereum/tx_10.json rename to testutil/testdata/ethereum/tx_10.json diff --git a/pkg/testdata/ethereum/tx_11.json b/testutil/testdata/ethereum/tx_11.json similarity index 100% rename from pkg/testdata/ethereum/tx_11.json rename to testutil/testdata/ethereum/tx_11.json diff --git a/pkg/testdata/ethereum/tx_12.json b/testutil/testdata/ethereum/tx_12.json similarity index 100% rename from pkg/testdata/ethereum/tx_12.json rename to testutil/testdata/ethereum/tx_12.json diff --git a/pkg/testdata/ethereum/tx_13.json b/testutil/testdata/ethereum/tx_13.json similarity index 100% rename from pkg/testdata/ethereum/tx_13.json rename to testutil/testdata/ethereum/tx_13.json diff --git a/pkg/testdata/ethereum/tx_14.json b/testutil/testdata/ethereum/tx_14.json similarity index 100% rename from pkg/testdata/ethereum/tx_14.json rename to testutil/testdata/ethereum/tx_14.json diff --git a/pkg/testdata/ethereum/tx_15.json b/testutil/testdata/ethereum/tx_15.json similarity index 100% rename from pkg/testdata/ethereum/tx_15.json rename to testutil/testdata/ethereum/tx_15.json diff --git a/pkg/testdata/ethereum/tx_16.json b/testutil/testdata/ethereum/tx_16.json similarity index 100% rename from pkg/testdata/ethereum/tx_16.json rename to testutil/testdata/ethereum/tx_16.json diff --git a/pkg/testdata/ethereum/tx_17.json b/testutil/testdata/ethereum/tx_17.json similarity index 100% rename from pkg/testdata/ethereum/tx_17.json rename to testutil/testdata/ethereum/tx_17.json diff --git a/pkg/testdata/ethereum/tx_18.json b/testutil/testdata/ethereum/tx_18.json similarity index 100% rename from pkg/testdata/ethereum/tx_18.json rename to testutil/testdata/ethereum/tx_18.json diff --git a/pkg/testdata/ethereum/tx_19.json b/testutil/testdata/ethereum/tx_19.json similarity index 100% rename from pkg/testdata/ethereum/tx_19.json rename to testutil/testdata/ethereum/tx_19.json diff --git a/pkg/testdata/ethereum/tx_2.json b/testutil/testdata/ethereum/tx_2.json similarity index 100% rename from pkg/testdata/ethereum/tx_2.json rename to testutil/testdata/ethereum/tx_2.json diff --git a/pkg/testdata/ethereum/tx_20.json b/testutil/testdata/ethereum/tx_20.json similarity index 100% rename from pkg/testdata/ethereum/tx_20.json rename to testutil/testdata/ethereum/tx_20.json diff --git a/pkg/testdata/ethereum/tx_21.json b/testutil/testdata/ethereum/tx_21.json similarity index 100% rename from pkg/testdata/ethereum/tx_21.json rename to testutil/testdata/ethereum/tx_21.json diff --git a/pkg/testdata/ethereum/tx_22.json b/testutil/testdata/ethereum/tx_22.json similarity index 100% rename from pkg/testdata/ethereum/tx_22.json rename to testutil/testdata/ethereum/tx_22.json diff --git a/pkg/testdata/ethereum/tx_23.json b/testutil/testdata/ethereum/tx_23.json similarity index 100% rename from pkg/testdata/ethereum/tx_23.json rename to testutil/testdata/ethereum/tx_23.json diff --git a/pkg/testdata/ethereum/tx_24.json b/testutil/testdata/ethereum/tx_24.json similarity index 100% rename from pkg/testdata/ethereum/tx_24.json rename to testutil/testdata/ethereum/tx_24.json diff --git a/pkg/testdata/ethereum/tx_25.json b/testutil/testdata/ethereum/tx_25.json similarity index 100% rename from pkg/testdata/ethereum/tx_25.json rename to testutil/testdata/ethereum/tx_25.json diff --git a/pkg/testdata/ethereum/tx_26.json b/testutil/testdata/ethereum/tx_26.json similarity index 100% rename from pkg/testdata/ethereum/tx_26.json rename to testutil/testdata/ethereum/tx_26.json diff --git a/pkg/testdata/ethereum/tx_27.json b/testutil/testdata/ethereum/tx_27.json similarity index 100% rename from pkg/testdata/ethereum/tx_27.json rename to testutil/testdata/ethereum/tx_27.json diff --git a/pkg/testdata/ethereum/tx_28.json b/testutil/testdata/ethereum/tx_28.json similarity index 100% rename from pkg/testdata/ethereum/tx_28.json rename to testutil/testdata/ethereum/tx_28.json diff --git a/pkg/testdata/ethereum/tx_29.json b/testutil/testdata/ethereum/tx_29.json similarity index 100% rename from pkg/testdata/ethereum/tx_29.json rename to testutil/testdata/ethereum/tx_29.json diff --git a/pkg/testdata/ethereum/tx_3.json b/testutil/testdata/ethereum/tx_3.json similarity index 100% rename from pkg/testdata/ethereum/tx_3.json rename to testutil/testdata/ethereum/tx_3.json diff --git a/pkg/testdata/ethereum/tx_30.json b/testutil/testdata/ethereum/tx_30.json similarity index 100% rename from pkg/testdata/ethereum/tx_30.json rename to testutil/testdata/ethereum/tx_30.json diff --git a/pkg/testdata/ethereum/tx_31.json b/testutil/testdata/ethereum/tx_31.json similarity index 100% rename from pkg/testdata/ethereum/tx_31.json rename to testutil/testdata/ethereum/tx_31.json diff --git a/pkg/testdata/ethereum/tx_32.json b/testutil/testdata/ethereum/tx_32.json similarity index 100% rename from pkg/testdata/ethereum/tx_32.json rename to testutil/testdata/ethereum/tx_32.json diff --git a/pkg/testdata/ethereum/tx_33.json b/testutil/testdata/ethereum/tx_33.json similarity index 100% rename from pkg/testdata/ethereum/tx_33.json rename to testutil/testdata/ethereum/tx_33.json diff --git a/pkg/testdata/ethereum/tx_34.json b/testutil/testdata/ethereum/tx_34.json similarity index 100% rename from pkg/testdata/ethereum/tx_34.json rename to testutil/testdata/ethereum/tx_34.json diff --git a/pkg/testdata/ethereum/tx_35.json b/testutil/testdata/ethereum/tx_35.json similarity index 100% rename from pkg/testdata/ethereum/tx_35.json rename to testutil/testdata/ethereum/tx_35.json diff --git a/pkg/testdata/ethereum/tx_36.json b/testutil/testdata/ethereum/tx_36.json similarity index 100% rename from pkg/testdata/ethereum/tx_36.json rename to testutil/testdata/ethereum/tx_36.json diff --git a/pkg/testdata/ethereum/tx_37.json b/testutil/testdata/ethereum/tx_37.json similarity index 100% rename from pkg/testdata/ethereum/tx_37.json rename to testutil/testdata/ethereum/tx_37.json diff --git a/pkg/testdata/ethereum/tx_38.json b/testutil/testdata/ethereum/tx_38.json similarity index 100% rename from pkg/testdata/ethereum/tx_38.json rename to testutil/testdata/ethereum/tx_38.json diff --git a/pkg/testdata/ethereum/tx_39.json b/testutil/testdata/ethereum/tx_39.json similarity index 100% rename from pkg/testdata/ethereum/tx_39.json rename to testutil/testdata/ethereum/tx_39.json diff --git a/pkg/testdata/ethereum/tx_4.json b/testutil/testdata/ethereum/tx_4.json similarity index 100% rename from pkg/testdata/ethereum/tx_4.json rename to testutil/testdata/ethereum/tx_4.json diff --git a/pkg/testdata/ethereum/tx_40.json b/testutil/testdata/ethereum/tx_40.json similarity index 100% rename from pkg/testdata/ethereum/tx_40.json rename to testutil/testdata/ethereum/tx_40.json diff --git a/pkg/testdata/ethereum/tx_41.json b/testutil/testdata/ethereum/tx_41.json similarity index 100% rename from pkg/testdata/ethereum/tx_41.json rename to testutil/testdata/ethereum/tx_41.json diff --git a/pkg/testdata/ethereum/tx_42.json b/testutil/testdata/ethereum/tx_42.json similarity index 100% rename from pkg/testdata/ethereum/tx_42.json rename to testutil/testdata/ethereum/tx_42.json diff --git a/pkg/testdata/ethereum/tx_43.json b/testutil/testdata/ethereum/tx_43.json similarity index 100% rename from pkg/testdata/ethereum/tx_43.json rename to testutil/testdata/ethereum/tx_43.json diff --git a/pkg/testdata/ethereum/tx_44.json b/testutil/testdata/ethereum/tx_44.json similarity index 100% rename from pkg/testdata/ethereum/tx_44.json rename to testutil/testdata/ethereum/tx_44.json diff --git a/pkg/testdata/ethereum/tx_45.json b/testutil/testdata/ethereum/tx_45.json similarity index 100% rename from pkg/testdata/ethereum/tx_45.json rename to testutil/testdata/ethereum/tx_45.json diff --git a/pkg/testdata/ethereum/tx_46.json b/testutil/testdata/ethereum/tx_46.json similarity index 100% rename from pkg/testdata/ethereum/tx_46.json rename to testutil/testdata/ethereum/tx_46.json diff --git a/pkg/testdata/ethereum/tx_47.json b/testutil/testdata/ethereum/tx_47.json similarity index 100% rename from pkg/testdata/ethereum/tx_47.json rename to testutil/testdata/ethereum/tx_47.json diff --git a/pkg/testdata/ethereum/tx_48.json b/testutil/testdata/ethereum/tx_48.json similarity index 100% rename from pkg/testdata/ethereum/tx_48.json rename to testutil/testdata/ethereum/tx_48.json diff --git a/pkg/testdata/ethereum/tx_49.json b/testutil/testdata/ethereum/tx_49.json similarity index 100% rename from pkg/testdata/ethereum/tx_49.json rename to testutil/testdata/ethereum/tx_49.json diff --git a/pkg/testdata/ethereum/tx_5.json b/testutil/testdata/ethereum/tx_5.json similarity index 100% rename from pkg/testdata/ethereum/tx_5.json rename to testutil/testdata/ethereum/tx_5.json diff --git a/pkg/testdata/ethereum/tx_50.json b/testutil/testdata/ethereum/tx_50.json similarity index 100% rename from pkg/testdata/ethereum/tx_50.json rename to testutil/testdata/ethereum/tx_50.json diff --git a/pkg/testdata/ethereum/tx_51.json b/testutil/testdata/ethereum/tx_51.json similarity index 100% rename from pkg/testdata/ethereum/tx_51.json rename to testutil/testdata/ethereum/tx_51.json diff --git a/pkg/testdata/ethereum/tx_52.json b/testutil/testdata/ethereum/tx_52.json similarity index 100% rename from pkg/testdata/ethereum/tx_52.json rename to testutil/testdata/ethereum/tx_52.json diff --git a/pkg/testdata/ethereum/tx_53.json b/testutil/testdata/ethereum/tx_53.json similarity index 100% rename from pkg/testdata/ethereum/tx_53.json rename to testutil/testdata/ethereum/tx_53.json diff --git a/pkg/testdata/ethereum/tx_54.json b/testutil/testdata/ethereum/tx_54.json similarity index 100% rename from pkg/testdata/ethereum/tx_54.json rename to testutil/testdata/ethereum/tx_54.json diff --git a/pkg/testdata/ethereum/tx_55.json b/testutil/testdata/ethereum/tx_55.json similarity index 100% rename from pkg/testdata/ethereum/tx_55.json rename to testutil/testdata/ethereum/tx_55.json diff --git a/pkg/testdata/ethereum/tx_56.json b/testutil/testdata/ethereum/tx_56.json similarity index 100% rename from pkg/testdata/ethereum/tx_56.json rename to testutil/testdata/ethereum/tx_56.json diff --git a/pkg/testdata/ethereum/tx_57.json b/testutil/testdata/ethereum/tx_57.json similarity index 100% rename from pkg/testdata/ethereum/tx_57.json rename to testutil/testdata/ethereum/tx_57.json diff --git a/pkg/testdata/ethereum/tx_58.json b/testutil/testdata/ethereum/tx_58.json similarity index 100% rename from pkg/testdata/ethereum/tx_58.json rename to testutil/testdata/ethereum/tx_58.json diff --git a/pkg/testdata/ethereum/tx_59.json b/testutil/testdata/ethereum/tx_59.json similarity index 100% rename from pkg/testdata/ethereum/tx_59.json rename to testutil/testdata/ethereum/tx_59.json diff --git a/pkg/testdata/ethereum/tx_6.json b/testutil/testdata/ethereum/tx_6.json similarity index 100% rename from pkg/testdata/ethereum/tx_6.json rename to testutil/testdata/ethereum/tx_6.json diff --git a/pkg/testdata/ethereum/tx_60.json b/testutil/testdata/ethereum/tx_60.json similarity index 100% rename from pkg/testdata/ethereum/tx_60.json rename to testutil/testdata/ethereum/tx_60.json diff --git a/pkg/testdata/ethereum/tx_61.json b/testutil/testdata/ethereum/tx_61.json similarity index 100% rename from pkg/testdata/ethereum/tx_61.json rename to testutil/testdata/ethereum/tx_61.json diff --git a/pkg/testdata/ethereum/tx_62.json b/testutil/testdata/ethereum/tx_62.json similarity index 100% rename from pkg/testdata/ethereum/tx_62.json rename to testutil/testdata/ethereum/tx_62.json diff --git a/pkg/testdata/ethereum/tx_63.json b/testutil/testdata/ethereum/tx_63.json similarity index 100% rename from pkg/testdata/ethereum/tx_63.json rename to testutil/testdata/ethereum/tx_63.json diff --git a/pkg/testdata/ethereum/tx_64.json b/testutil/testdata/ethereum/tx_64.json similarity index 100% rename from pkg/testdata/ethereum/tx_64.json rename to testutil/testdata/ethereum/tx_64.json diff --git a/pkg/testdata/ethereum/tx_65.json b/testutil/testdata/ethereum/tx_65.json similarity index 100% rename from pkg/testdata/ethereum/tx_65.json rename to testutil/testdata/ethereum/tx_65.json diff --git a/pkg/testdata/ethereum/tx_66.json b/testutil/testdata/ethereum/tx_66.json similarity index 100% rename from pkg/testdata/ethereum/tx_66.json rename to testutil/testdata/ethereum/tx_66.json diff --git a/pkg/testdata/ethereum/tx_67.json b/testutil/testdata/ethereum/tx_67.json similarity index 100% rename from pkg/testdata/ethereum/tx_67.json rename to testutil/testdata/ethereum/tx_67.json diff --git a/pkg/testdata/ethereum/tx_68.json b/testutil/testdata/ethereum/tx_68.json similarity index 100% rename from pkg/testdata/ethereum/tx_68.json rename to testutil/testdata/ethereum/tx_68.json diff --git a/pkg/testdata/ethereum/tx_69.json b/testutil/testdata/ethereum/tx_69.json similarity index 100% rename from pkg/testdata/ethereum/tx_69.json rename to testutil/testdata/ethereum/tx_69.json diff --git a/pkg/testdata/ethereum/tx_7.json b/testutil/testdata/ethereum/tx_7.json similarity index 100% rename from pkg/testdata/ethereum/tx_7.json rename to testutil/testdata/ethereum/tx_7.json diff --git a/pkg/testdata/ethereum/tx_70.json b/testutil/testdata/ethereum/tx_70.json similarity index 100% rename from pkg/testdata/ethereum/tx_70.json rename to testutil/testdata/ethereum/tx_70.json diff --git a/pkg/testdata/ethereum/tx_71.json b/testutil/testdata/ethereum/tx_71.json similarity index 100% rename from pkg/testdata/ethereum/tx_71.json rename to testutil/testdata/ethereum/tx_71.json diff --git a/pkg/testdata/ethereum/tx_72.json b/testutil/testdata/ethereum/tx_72.json similarity index 100% rename from pkg/testdata/ethereum/tx_72.json rename to testutil/testdata/ethereum/tx_72.json diff --git a/pkg/testdata/ethereum/tx_73.json b/testutil/testdata/ethereum/tx_73.json similarity index 100% rename from pkg/testdata/ethereum/tx_73.json rename to testutil/testdata/ethereum/tx_73.json diff --git a/pkg/testdata/ethereum/tx_74.json b/testutil/testdata/ethereum/tx_74.json similarity index 100% rename from pkg/testdata/ethereum/tx_74.json rename to testutil/testdata/ethereum/tx_74.json diff --git a/pkg/testdata/ethereum/tx_75.json b/testutil/testdata/ethereum/tx_75.json similarity index 100% rename from pkg/testdata/ethereum/tx_75.json rename to testutil/testdata/ethereum/tx_75.json diff --git a/pkg/testdata/ethereum/tx_76.json b/testutil/testdata/ethereum/tx_76.json similarity index 100% rename from pkg/testdata/ethereum/tx_76.json rename to testutil/testdata/ethereum/tx_76.json diff --git a/pkg/testdata/ethereum/tx_77.json b/testutil/testdata/ethereum/tx_77.json similarity index 100% rename from pkg/testdata/ethereum/tx_77.json rename to testutil/testdata/ethereum/tx_77.json diff --git a/pkg/testdata/ethereum/tx_78.json b/testutil/testdata/ethereum/tx_78.json similarity index 100% rename from pkg/testdata/ethereum/tx_78.json rename to testutil/testdata/ethereum/tx_78.json diff --git a/pkg/testdata/ethereum/tx_79.json b/testutil/testdata/ethereum/tx_79.json similarity index 100% rename from pkg/testdata/ethereum/tx_79.json rename to testutil/testdata/ethereum/tx_79.json diff --git a/pkg/testdata/ethereum/tx_8.json b/testutil/testdata/ethereum/tx_8.json similarity index 100% rename from pkg/testdata/ethereum/tx_8.json rename to testutil/testdata/ethereum/tx_8.json diff --git a/pkg/testdata/ethereum/tx_80.json b/testutil/testdata/ethereum/tx_80.json similarity index 100% rename from pkg/testdata/ethereum/tx_80.json rename to testutil/testdata/ethereum/tx_80.json diff --git a/pkg/testdata/ethereum/tx_9.json b/testutil/testdata/ethereum/tx_9.json similarity index 100% rename from pkg/testdata/ethereum/tx_9.json rename to testutil/testdata/ethereum/tx_9.json diff --git a/pkg/testdata/test_blocks.json b/testutil/testdata/test_blocks.json similarity index 100% rename from pkg/testdata/test_blocks.json rename to testutil/testdata/test_blocks.json diff --git a/pkg/testdata/testdata.go b/testutil/testdata/testdata.go similarity index 100% rename from pkg/testdata/testdata.go rename to testutil/testdata/testdata.go diff --git a/pkg/testdata/types/chain_info.json b/testutil/testdata/types/chain_info.json similarity index 100% rename from pkg/testdata/types/chain_info.json rename to testutil/testdata/types/chain_info.json diff --git a/pkg/testdata/types/policies.json b/testutil/testdata/types/policies.json similarity index 100% rename from pkg/testdata/types/policies.json rename to testutil/testdata/types/policies.json diff --git a/x/authority/client/cli/tx_update_chain_info_test.go b/x/authority/client/cli/tx_update_chain_info_test.go index 95b033777f..2d04a82b29 100644 --- a/x/authority/client/cli/tx_update_chain_info_test.go +++ b/x/authority/client/cli/tx_update_chain_info_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/pkg/testdata" + "github.com/zeta-chain/zetacore/testutil/testdata" "github.com/zeta-chain/zetacore/x/authority/client/cli" ) diff --git a/x/authority/client/cli/tx_update_policies_test.go b/x/authority/client/cli/tx_update_policies_test.go index 45e6813fcb..35756605c9 100644 --- a/x/authority/client/cli/tx_update_policies_test.go +++ b/x/authority/client/cli/tx_update_policies_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/zeta-chain/zetacore/pkg/testdata" + "github.com/zeta-chain/zetacore/testutil/testdata" "github.com/zeta-chain/zetacore/x/authority/client/cli" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" ) diff --git a/x/observer/types/message_vote_block_header_test.go b/x/observer/types/message_vote_block_header_test.go index 192d164d43..763114c122 100644 --- a/x/observer/types/message_vote_block_header_test.go +++ b/x/observer/types/message_vote_block_header_test.go @@ -20,7 +20,7 @@ import ( func TestMsgVoteBlockHeader_ValidateBasic(t *testing.T) { keeper.SetConfig(false) var header ethtypes.Header - file, err := os.Open("../../../pkg/testdata/eth_header_18495266.json") + file, err := os.Open("../../../testutil/testdata/eth_header_18495266.json") require.NoError(t, err) defer file.Close() headerBytes := make([]byte, 4096) diff --git a/zetaclient/zetacore/tx_test.go b/zetaclient/zetacore/tx_test.go index 919f9cc058..bd860bc894 100644 --- a/zetaclient/zetacore/tx_test.go +++ b/zetaclient/zetacore/tx_test.go @@ -123,7 +123,7 @@ func MockBroadcastError(_ *Client, _ uint64, _ sdktypes.Msg, _ authz.Signer) (st func getHeaderData(t *testing.T) proofs.HeaderData { var header ethtypes.Header - file, err := os.Open("../../pkg/testdata/eth_header_18495266.json") + file, err := os.Open("../../testutil/testdata/eth_header_18495266.json") require.NoError(t, err) defer file.Close() headerBytes := make([]byte, 4096) From c93d1c6057f4278bacf434648f8daafd342fcfd3 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Tue, 4 Jun 2024 08:23:37 -0700 Subject: [PATCH 5/6] fix: adjust upgrade orchestrator scp quoting (#2309) --- contrib/localnet/scripts/start-upgrade-orchestrator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/localnet/scripts/start-upgrade-orchestrator.sh b/contrib/localnet/scripts/start-upgrade-orchestrator.sh index fb7bfe7a52..a2e8ec68fd 100755 --- a/contrib/localnet/scripts/start-upgrade-orchestrator.sh +++ b/contrib/localnet/scripts/start-upgrade-orchestrator.sh @@ -34,7 +34,7 @@ done # copy zetacore0 config and keys if not running on zetacore0 if [[ $(hostname) != "zetacore0" ]]; then - scp -r zetacore0:"~/.zetacored/config ~/.zetacored/os_info ~/.zetacored/config ~/.zetacored/keyring-file ~/.zetacored/keyring-test" ~/.zetacored/ + scp -r 'zetacore0:~/.zetacored/config' 'zetacore0:~/.zetacored/os_info' 'zetacore0:~/.zetacored/config' 'zetacore0:~/.zetacored/keyring-file' 'zetacore0:~/.zetacored/keyring-test' ~/.zetacored/ sed -i 's|tcp://localhost:26657|tcp://zetacore0:26657|g' ~/.zetacored/config/client.toml fi From 26b4f69521b8316a74a2d65ff0bbbd0f386b0cfa Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 4 Jun 2024 13:27:04 -0400 Subject: [PATCH 6/6] feat: add MsgAddAuthorization to add or update and authorization and MsgRemoveAuthorization to remove a authorization (#2305) --- changelog.md | 1 + docs/cli/zetacored/zetacored_tx_authority.md | 4 +- ...etacored_tx_authority_add-authorization.md | 53 + ...cored_tx_authority_remove-authorization.md | 53 + .../zetacored_tx_authority_update-policies.md | 2 +- docs/openapi/openapi.swagger.yaml | 12 + docs/spec/authority/messages.md | 24 + .../zetacore/authority/policies.proto | 1 + proto/zetachain/zetacore/authority/tx.proto | 27 + testutil/keeper/authority.go | 2 +- .../zetacore/authority/policies_pb.d.ts | 9 + .../zetachain/zetacore/authority/tx_pb.d.ts | 115 ++- x/authority/client/cli/tx.go | 4 +- .../client/cli/tx_add_authorization.go | 61 ++ .../client/cli/tx_add_authorizations_test.go | 60 ++ .../client/cli/tx_remove_authorization.go | 34 + x/authority/client/cli/tx_update_policies.go | 4 +- .../keeper/msg_server_add_authorization.go | 41 + .../msg_server_add_authorization_test.go | 219 +++++ .../keeper/msg_server_remove_authorization.go | 51 + .../msg_server_remove_authorization_test.go | 204 ++++ x/authority/types/authorizations.go | 15 +- x/authority/types/authorizations_test.go | 59 +- x/authority/types/errors.go | 7 +- .../types/message_add_authorization.go | 65 ++ .../types/message_add_authorizations_test.go | 130 +++ .../types/message_remove_authorization.go | 51 + .../message_remove_authorizations_test.go | 97 ++ x/authority/types/policies.go | 5 +- x/authority/types/policies.pb.go | 45 +- x/authority/types/policy_type.go | 13 + x/authority/types/policy_type_test.go | 58 ++ x/authority/types/tx.pb.go | 916 ++++++++++++++++-- x/crosschain/keeper/evm_hooks_test.go | 12 +- 34 files changed, 2330 insertions(+), 124 deletions(-) create mode 100644 docs/cli/zetacored/zetacored_tx_authority_add-authorization.md create mode 100644 docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md create mode 100644 x/authority/client/cli/tx_add_authorization.go create mode 100644 x/authority/client/cli/tx_add_authorizations_test.go create mode 100644 x/authority/client/cli/tx_remove_authorization.go create mode 100644 x/authority/keeper/msg_server_add_authorization.go create mode 100644 x/authority/keeper/msg_server_add_authorization_test.go create mode 100644 x/authority/keeper/msg_server_remove_authorization.go create mode 100644 x/authority/keeper/msg_server_remove_authorization_test.go create mode 100644 x/authority/types/message_add_authorization.go create mode 100644 x/authority/types/message_add_authorizations_test.go create mode 100644 x/authority/types/message_remove_authorization.go create mode 100644 x/authority/types/message_remove_authorizations_test.go create mode 100644 x/authority/types/policy_type.go create mode 100644 x/authority/types/policy_type_test.go diff --git a/changelog.md b/changelog.md index 82d90197d2..dbf40ef8e3 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,7 @@ * [2275](https://github.com/zeta-chain/node/pull/2275) - add ChainInfo singleton state variable in authority * [2291](https://github.com/zeta-chain/node/pull/2291) - initialize cctx gateway interface * [2289](https://github.com/zeta-chain/node/pull/2289) - add an authorization list to keep track of all authorizations on the chain +* [2305](https://github.com/zeta-chain/node/pull/2305) - add new messages `MsgAddAuthorization` and `MsgRemoveAuthorization` that can be used to update the authorization list ### Refactor diff --git a/docs/cli/zetacored/zetacored_tx_authority.md b/docs/cli/zetacored/zetacored_tx_authority.md index 5a543e70b1..59a0ca9ffa 100644 --- a/docs/cli/zetacored/zetacored_tx_authority.md +++ b/docs/cli/zetacored/zetacored_tx_authority.md @@ -26,6 +26,8 @@ zetacored tx authority [flags] ### SEE ALSO * [zetacored tx](zetacored_tx.md) - Transactions subcommands +* [zetacored tx authority add-authorization](zetacored_tx_authority_add-authorization.md) - Add a new authorization or update the policy of an existing authorization. Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin. +* [zetacored tx authority remove-authorization](zetacored_tx_authority_remove-authorization.md) - removes an existing authorization * [zetacored tx authority update-chain-info](zetacored_tx_authority_update-chain-info.md) - Update the chain info -* [zetacored tx authority update-policies](zetacored_tx_authority_update-policies.md) - Update the policies +* [zetacored tx authority update-policies](zetacored_tx_authority_update-policies.md) - Update policies to values provided in the JSON file. diff --git a/docs/cli/zetacored/zetacored_tx_authority_add-authorization.md b/docs/cli/zetacored/zetacored_tx_authority_add-authorization.md new file mode 100644 index 0000000000..4ed717b2b6 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_authority_add-authorization.md @@ -0,0 +1,53 @@ +# tx authority add-authorization + +Add a new authorization or update the policy of an existing authorization. Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin. + +``` +zetacored tx authority add-authorization [msg-url] [authorized-policy] [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async) + --chain-id string The network chain ID + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for add-authorization + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --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 tx authority](zetacored_tx_authority.md) - authority transactions subcommands + diff --git a/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md b/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md new file mode 100644 index 0000000000..a29a02bb18 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md @@ -0,0 +1,53 @@ +# tx authority remove-authorization + +removes an existing authorization + +``` +zetacored tx authority remove-authorization [msg-url] [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async) + --chain-id string The network chain ID + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for remove-authorization + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --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 tx authority](zetacored_tx_authority.md) - authority transactions subcommands + diff --git a/docs/cli/zetacored/zetacored_tx_authority_update-policies.md b/docs/cli/zetacored/zetacored_tx_authority_update-policies.md index c26e3f0080..7e375d8d1e 100644 --- a/docs/cli/zetacored/zetacored_tx_authority_update-policies.md +++ b/docs/cli/zetacored/zetacored_tx_authority_update-policies.md @@ -1,6 +1,6 @@ # tx authority update-policies -Update the policies +Update policies to values provided in the JSON file. ``` zetacored tx authority update-policies [policies-json-file] [flags] diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index c9e758227f..8bb38c8a67 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -56730,6 +56730,14 @@ definitions: ChainInfo contains static information about the chains This structure is used to dynamically update these info on a live network before hardcoding the values in a upgrade + authorityMsgAddAuthorizationResponse: + type: object + description: MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. + authorityMsgRemoveAuthorizationResponse: + type: object + description: |- + MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse + service. authorityMsgUpdateChainInfoResponse: type: object description: MsgUpdateChainInfoResponse defines the MsgUpdateChainInfoResponse service. @@ -56758,6 +56766,7 @@ definitions: - groupEmergency - groupOperational - groupAdmin + - groupEmpty default: groupEmergency description: |- - groupEmergency: Used for emergency situations that require immediate action @@ -56765,6 +56774,9 @@ definitions: - groupAdmin: non-sensitive protocol parameters Used for administrative tasks like changing sensitive + - groupEmpty: protocol parameters or moving funds + + Used for empty policy, no action is allowed title: PolicyType defines the type of policy authorityQueryGetChainInfoResponse: type: object diff --git a/docs/spec/authority/messages.md b/docs/spec/authority/messages.md index 899a95b989..8ee4264bab 100644 --- a/docs/spec/authority/messages.md +++ b/docs/spec/authority/messages.md @@ -23,3 +23,27 @@ message MsgUpdateChainInfo { } ``` +## MsgAddAuthorization + +AddAuthorization defines a method to add an authorization.If the authorization already exists, it will be overwritten with the provided policy. +This should be called by the admin policy account. + +```proto +message MsgAddAuthorization { + string creator = 1; + string msg_url = 2; + PolicyType authorized_policy = 3; +} +``` + +## MsgRemoveAuthorization + +RemoveAuthorization removes the authorization from the list. It should be called by the admin policy account. + +```proto +message MsgRemoveAuthorization { + string creator = 1; + string msg_url = 2; +} +``` + diff --git a/proto/zetachain/zetacore/authority/policies.proto b/proto/zetachain/zetacore/authority/policies.proto index b02f448514..faefdbf2c7 100644 --- a/proto/zetachain/zetacore/authority/policies.proto +++ b/proto/zetachain/zetacore/authority/policies.proto @@ -14,6 +14,7 @@ enum PolicyType { // non-sensitive protocol parameters groupAdmin = 2; // Used for administrative tasks like changing sensitive // protocol parameters or moving funds + groupEmpty = 3; // Used for empty policy, no action is allowed } message Policy { diff --git a/proto/zetachain/zetacore/authority/tx.proto b/proto/zetachain/zetacore/authority/tx.proto index 55509e3172..29b1b44362 100644 --- a/proto/zetachain/zetacore/authority/tx.proto +++ b/proto/zetachain/zetacore/authority/tx.proto @@ -12,8 +12,35 @@ option go_package = "github.com/zeta-chain/zetacore/x/authority/types"; service Msg { rpc UpdatePolicies(MsgUpdatePolicies) returns (MsgUpdatePoliciesResponse); rpc UpdateChainInfo(MsgUpdateChainInfo) returns (MsgUpdateChainInfoResponse); + rpc AddAuthorization(MsgAddAuthorization) + returns (MsgAddAuthorizationResponse); + rpc RemoveAuthorization(MsgRemoveAuthorization) + returns (MsgRemoveAuthorizationResponse); } +// MsgAddAuthorization defines the MsgAddAuthorization service. +// Adds an authorization to the chain. If the authorization already exists, it +// will be updated. +message MsgAddAuthorization { + string creator = 1; + string msg_url = 2; + PolicyType authorized_policy = 3; +} + +// MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. +message MsgAddAuthorizationResponse {} + +// MsgRemoveAuthorization defines the MsgRemoveAuthorization service. +// Removes an authorization from the chain. +message MsgRemoveAuthorization { + string creator = 1; + string msg_url = 2; +} + +// MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse +// service. +message MsgRemoveAuthorizationResponse {} + // MsgUpdatePolicies defines the MsgUpdatePolicies service. message MsgUpdatePolicies { string creator = 1; diff --git a/testutil/keeper/authority.go b/testutil/keeper/authority.go index 3e7f98b506..be9101d1df 100644 --- a/testutil/keeper/authority.go +++ b/testutil/keeper/authority.go @@ -79,7 +79,7 @@ func MockIsAuthorized(m *mock.Mock, address string, policyType types.PolicyType, m.On("IsAuthorized", mock.Anything, address, policyType).Return(isAuthorized).Once() } -func SetAdminPolices(ctx sdk.Context, ak *keeper.Keeper) string { +func SetAdminPolicies(ctx sdk.Context, ak *keeper.Keeper) string { admin := sample.AccAddress() ak.SetPolicies(ctx, types.Policies{Items: []*types.Policy{ { diff --git a/typescript/zetachain/zetacore/authority/policies_pb.d.ts b/typescript/zetachain/zetacore/authority/policies_pb.d.ts index 21646f273a..8bf6b71c00 100644 --- a/typescript/zetachain/zetacore/authority/policies_pb.d.ts +++ b/typescript/zetachain/zetacore/authority/policies_pb.d.ts @@ -34,6 +34,15 @@ export declare enum PolicyType { * @generated from enum value: groupAdmin = 2; */ groupAdmin = 2, + + /** + * protocol parameters or moving funds + * + * Used for empty policy, no action is allowed + * + * @generated from enum value: groupEmpty = 3; + */ + groupEmpty = 3, } /** diff --git a/typescript/zetachain/zetacore/authority/tx_pb.d.ts b/typescript/zetachain/zetacore/authority/tx_pb.d.ts index bd531ac2e5..827b942c9b 100644 --- a/typescript/zetachain/zetacore/authority/tx_pb.d.ts +++ b/typescript/zetachain/zetacore/authority/tx_pb.d.ts @@ -5,9 +5,122 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; -import type { Policies } from "./policies_pb.js"; +import type { Policies, PolicyType } from "./policies_pb.js"; import type { ChainInfo } from "./chain_info_pb.js"; +/** + * MsgAddAuthorization defines the MsgAddAuthorization service. + * Adds an authorization to the chain. If the authorization already exists, it + * will be updated. + * + * @generated from message zetachain.zetacore.authority.MsgAddAuthorization + */ +export declare class MsgAddAuthorization extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: string msg_url = 2; + */ + msgUrl: string; + + /** + * @generated from field: zetachain.zetacore.authority.PolicyType authorized_policy = 3; + */ + authorizedPolicy: PolicyType; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgAddAuthorization"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddAuthorization; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddAuthorization; + + static fromJsonString(jsonString: string, options?: Partial): MsgAddAuthorization; + + static equals(a: MsgAddAuthorization | PlainMessage | undefined, b: MsgAddAuthorization | PlainMessage | undefined): boolean; +} + +/** + * MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. + * + * @generated from message zetachain.zetacore.authority.MsgAddAuthorizationResponse + */ +export declare class MsgAddAuthorizationResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgAddAuthorizationResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddAuthorizationResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddAuthorizationResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgAddAuthorizationResponse; + + static equals(a: MsgAddAuthorizationResponse | PlainMessage | undefined, b: MsgAddAuthorizationResponse | PlainMessage | undefined): boolean; +} + +/** + * MsgRemoveAuthorization defines the MsgRemoveAuthorization service. + * Removes an authorization from the chain. + * + * @generated from message zetachain.zetacore.authority.MsgRemoveAuthorization + */ +export declare class MsgRemoveAuthorization extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: string msg_url = 2; + */ + msgUrl: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgRemoveAuthorization"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgRemoveAuthorization; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgRemoveAuthorization; + + static fromJsonString(jsonString: string, options?: Partial): MsgRemoveAuthorization; + + static equals(a: MsgRemoveAuthorization | PlainMessage | undefined, b: MsgRemoveAuthorization | PlainMessage | undefined): boolean; +} + +/** + * MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse + * service. + * + * @generated from message zetachain.zetacore.authority.MsgRemoveAuthorizationResponse + */ +export declare class MsgRemoveAuthorizationResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgRemoveAuthorizationResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgRemoveAuthorizationResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgRemoveAuthorizationResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgRemoveAuthorizationResponse; + + static equals(a: MsgRemoveAuthorizationResponse | PlainMessage | undefined, b: MsgRemoveAuthorizationResponse | PlainMessage | undefined): boolean; +} + /** * MsgUpdatePolicies defines the MsgUpdatePolicies service. * diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index 1455773bf5..8c1c1396db 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -20,8 +20,10 @@ func GetTxCmd() *cobra.Command { } cmd.AddCommand( - CmdUpdatePolices(), + CmdUpdatePolicies(), CmdUpdateChainInfo(), + CmdAddAuthorization(), + CmdRemoveAuthorization(), ) return cmd diff --git a/x/authority/client/cli/tx_add_authorization.go b/x/authority/client/cli/tx_add_authorization.go new file mode 100644 index 0000000000..5658d24e91 --- /dev/null +++ b/x/authority/client/cli/tx_add_authorization.go @@ -0,0 +1,61 @@ +package cli + +import ( + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func CmdAddAuthorization() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-authorization [msg-url] [authorized-policy]", + Short: "Add a new authorization or update the policy of an existing authorization. Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin.", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + authorizedPolicy, err := GetPolicyType(args[1]) + if err != nil { + return err + } + msg := &types.MsgAddAuthorization{ + MsgUrl: args[0], + AuthorizedPolicy: authorizedPolicy, + } + err = msg.ValidateBasic() + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +func GetPolicyType(policyTypeString string) (types.PolicyType, error) { + policyType, err := strconv.ParseInt(policyTypeString, 10, 64) + if err != nil { + return types.PolicyType_groupEmpty, fmt.Errorf("failed to parse policy type: %w", err) + } + + switch policyType { + case 0: + return types.PolicyType_groupEmergency, nil + case 1: + return types.PolicyType_groupOperational, nil + case 2: + return types.PolicyType_groupAdmin, nil + default: + return types.PolicyType_groupEmpty, fmt.Errorf("invalid policy type value: %d", policyType) + } + +} diff --git a/x/authority/client/cli/tx_add_authorizations_test.go b/x/authority/client/cli/tx_add_authorizations_test.go new file mode 100644 index 0000000000..5c5042ee36 --- /dev/null +++ b/x/authority/client/cli/tx_add_authorizations_test.go @@ -0,0 +1,60 @@ +package cli_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/x/authority/client/cli" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func Test_GetPolicyType(t *testing.T) { + tt := []struct { + name string + policyTypeString string + expectedPolicyType types.PolicyType + expecterErrorString string + }{ + { + name: "groupEmergency", + policyTypeString: "0", + expectedPolicyType: types.PolicyType_groupEmergency, + expecterErrorString: "", + }, + { + name: "groupOperational", + policyTypeString: "1", + expectedPolicyType: types.PolicyType_groupOperational, + expecterErrorString: "", + }, + { + name: "groupAdmin", + policyTypeString: "2", + expectedPolicyType: types.PolicyType_groupAdmin, + expecterErrorString: "", + }, + { + name: "groupEmpty", + policyTypeString: "3", + expectedPolicyType: types.PolicyType_groupEmpty, + expecterErrorString: "invalid policy type value", + }, + { + name: "string literal for policy type not accepted", + policyTypeString: "groupEmergency", + expectedPolicyType: types.PolicyType_groupEmpty, + expecterErrorString: "failed to parse policy type", + }, + } + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + policyType, err := cli.GetPolicyType(tc.policyTypeString) + require.Equal(t, tc.expectedPolicyType, policyType) + if tc.expectedPolicyType == types.PolicyType_groupEmpty { + require.ErrorContains(t, err, tc.expecterErrorString) + } + }) + } + +} diff --git a/x/authority/client/cli/tx_remove_authorization.go b/x/authority/client/cli/tx_remove_authorization.go new file mode 100644 index 0000000000..3fee09f12f --- /dev/null +++ b/x/authority/client/cli/tx_remove_authorization.go @@ -0,0 +1,34 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func CmdRemoveAuthorization() *cobra.Command { + cmd := &cobra.Command{ + Use: "remove-authorization [msg-url]", + Short: "removes an existing authorization", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + msg := &types.MsgRemoveAuthorization{ + MsgUrl: args[0], + } + err = msg.ValidateBasic() + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} diff --git a/x/authority/client/cli/tx_update_policies.go b/x/authority/client/cli/tx_update_policies.go index 19bfe6ab4f..69b8cd71f0 100644 --- a/x/authority/client/cli/tx_update_policies.go +++ b/x/authority/client/cli/tx_update_policies.go @@ -14,10 +14,10 @@ import ( "github.com/zeta-chain/zetacore/x/authority/types" ) -func CmdUpdatePolices() *cobra.Command { +func CmdUpdatePolicies() *cobra.Command { cmd := &cobra.Command{ Use: "update-policies [policies-json-file]", - Short: "Update the policies", + Short: "Update policies to values provided in the JSON file.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { policies, err := ReadPoliciesFromFile(os.DirFS("."), args[0]) diff --git a/x/authority/keeper/msg_server_add_authorization.go b/x/authority/keeper/msg_server_add_authorization.go new file mode 100644 index 0000000000..252884cd3f --- /dev/null +++ b/x/authority/keeper/msg_server_add_authorization.go @@ -0,0 +1,41 @@ +package keeper + +import ( + "context" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +// AddAuthorization defines a method to add an authorization.If the authorization already exists, it will be overwritten with the provided policy. +// This should be called by the admin policy account. +func (k msgServer) AddAuthorization( + goCtx context.Context, + msg *types.MsgAddAuthorization, +) (*types.MsgAddAuthorizationResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if !k.IsAuthorized(ctx, msg.Creator, types.PolicyType_groupAdmin) { + return nil, errorsmod.Wrap( + types.ErrUnauthorized, + "AddAuthorization can only be executed by the admin policy account", + ) + } + + authorizationList, found := k.GetAuthorizationList(ctx) + if !found { + authorizationList = types.AuthorizationList{Authorizations: []types.Authorization{}} + } + authorizationList.SetAuthorization(types.Authorization{MsgUrl: msg.MsgUrl, AuthorizedPolicy: msg.AuthorizedPolicy}) + + // validate the authorization list after adding the authorization as a precautionary measure. + err := authorizationList.Validate() + if err != nil { + return nil, errorsmod.Wrap(err, "authorization list is invalid") + } + + k.SetAuthorizationList(ctx, authorizationList) + return &types.MsgAddAuthorizationResponse{}, nil +} diff --git a/x/authority/keeper/msg_server_add_authorization_test.go b/x/authority/keeper/msg_server_add_authorization_test.go new file mode 100644 index 0000000000..95c962951e --- /dev/null +++ b/x/authority/keeper/msg_server_add_authorization_test.go @@ -0,0 +1,219 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/keeper" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgServer_AddAuthorization(t *testing.T) { + const url = "/zetachain.zetacore.sample.ABC" + t.Run("successfully add authorization of type admin to existing authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + require.Equal(t, prevLen+1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully add authorization of type operational to existing authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupOperational, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupOperational, policy) + require.Equal(t, prevLen+1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully add authorization of type emergency to existing authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupEmergency, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupEmergency, policy) + require.Equal(t, prevLen+1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully add authorization to empty authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.AuthorizationList{}) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + require.Equal(t, 1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully set authorization when list is not found ", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + msgServer := keeper.NewMsgServerImpl(*k) + authorizationList, found := k.GetAuthorizationList(ctx) + require.False(t, found) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + require.Equal(t, 1, len(authorizationList.Authorizations)) + }) + + t.Run("update existing authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "/zetachain.zetacore.sample.ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }, + } + k.SetAuthorizationList(ctx, authorizationList) + prevLen := len(authorizationList.Authorizations) + + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + require.Equal(t, prevLen, len(authorizationList.Authorizations)) + }) + + t.Run("fail to add authorization with invalid policy as creator", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: sample.AccAddress(), + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrUnauthorized) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, prevLen, len(authorizationList.Authorizations)) + }) + + // This scenario is not possible as the authorization list is always valid.But it is good to have in case the validation logic is changed in the future + t.Run("fail to set invalid authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }} + k.SetAuthorizationList(ctx, authorizationList) + prevLen := len(authorizationList.Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrInvalidAuthorizationList) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, prevLen, len(authorizationList.Authorizations)) + }) +} diff --git a/x/authority/keeper/msg_server_remove_authorization.go b/x/authority/keeper/msg_server_remove_authorization.go new file mode 100644 index 0000000000..f84e2fdffe --- /dev/null +++ b/x/authority/keeper/msg_server_remove_authorization.go @@ -0,0 +1,51 @@ +package keeper + +import ( + "context" + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +// RemoveAuthorization defines a method to remove an authorization. +// This should be called by the admin policy account. +func (k msgServer) RemoveAuthorization( + goCtx context.Context, + msg *types.MsgRemoveAuthorization, +) (*types.MsgRemoveAuthorizationResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if !k.IsAuthorized(ctx, msg.Creator, types.PolicyType_groupAdmin) { + return nil, errorsmod.Wrap( + types.ErrUnauthorized, + "RemoveAuthorization can only be executed by the admin policy account", + ) + } + + // check if the authorization list exists, we can return early if there is no list. + authorizationList, found := k.GetAuthorizationList(ctx) + if !found { + return nil, types.ErrAuthorizationListNotFound + } + + // check if the authorization exists, we can return early if the authorization does not exist. + _, err := authorizationList.GetAuthorizedPolicy(msg.MsgUrl) + if err != nil { + return nil, errorsmod.Wrap(err, fmt.Sprintf("msg url %s", msg.MsgUrl)) + } + + // remove the authorization + authorizationList.RemoveAuthorization(msg.MsgUrl) + + // validate the authorization list after adding the authorization as a precautionary measure. + err = authorizationList.Validate() + if err != nil { + return nil, errorsmod.Wrap(err, "authorization list is invalid") + } + k.SetAuthorizationList(ctx, authorizationList) + + return &types.MsgRemoveAuthorizationResponse{}, nil +} diff --git a/x/authority/keeper/msg_server_remove_authorization_test.go b/x/authority/keeper/msg_server_remove_authorization_test.go new file mode 100644 index 0000000000..566369839a --- /dev/null +++ b/x/authority/keeper/msg_server_remove_authorization_test.go @@ -0,0 +1,204 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/keeper" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgServer_RemoveAuthorization(t *testing.T) { + t.Run("successfully remove operational policy authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.OperationPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + _, err = authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + require.Equal(t, prevLen-1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully remove admin policy authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.AdminPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + _, err = authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + require.Equal(t, prevLen-1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully remove emergency policy authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.EmergencyPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + _, err = authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + require.Equal(t, prevLen-1, len(authorizationList.Authorizations)) + }) + + t.Run("unable to remove authorization if creator is not the correct policy", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.OperationPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: sample.AccAddress(), + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrUnauthorized) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, types.DefaultAuthorizationsList(), authorizationList) + require.Equal(t, prevLen, len(authorizationList.Authorizations)) + }) + + t.Run("unable to remove authorization if authorization list does not exist", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.OperationPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + _, err := msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrAuthorizationListNotFound) + }) + + t.Run("unable to remove authorization if authorization does not exist", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }} + k.SetAuthorizationList(ctx, authorizationList) + msgServer := keeper.NewMsgServerImpl(*k) + url := "invalid" + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + + authorizationListNew, found := k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, authorizationList, authorizationListNew) + }) + + t.Run("unable to remove authorization if authorization list is invalid", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }} + k.SetAuthorizationList(ctx, authorizationList) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: "ABC", + } + + _, err := msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrInvalidAuthorizationList) + + authorizationListNew, found := k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, authorizationList, authorizationListNew) + }) +} diff --git a/x/authority/types/authorizations.go b/x/authority/types/authorizations.go index 0de98a768e..848b1da1d2 100644 --- a/x/authority/types/authorizations.go +++ b/x/authority/types/authorizations.go @@ -34,6 +34,8 @@ var ( "/zetachain.zetacore.fungible.MsgUpdateContractBytecode", "/zetachain.zetacore.fungible.MsgUpdateSystemContract", "/zetachain.zetacore.observer.MsgUpdateObserver", + "/zetachain.zetacore.authority.MsgAddAuthorization", + "/zetachain.zetacore.authority.MsgRemoveAuthorization", } // EmergencyPolicyMessages keeps track of the message URLs that can, by default, only be executed by emergency policy address EmergencyPolicyMessages = []string{ @@ -93,25 +95,24 @@ func (a *AuthorizationList) SetAuthorization(authorization Authorization) { a.Authorizations = append(a.Authorizations, authorization) } -// RemoveAuthorization removes the authorization from the list. It does not check if the authorization exists or not. -func (a *AuthorizationList) RemoveAuthorization(authorization Authorization) { +// RemoveAuthorization removes the authorization from the list. It should be called by the admin policy account. +func (a *AuthorizationList) RemoveAuthorization(msgURL string) { for i, auth := range a.Authorizations { - if auth.MsgUrl == authorization.MsgUrl { + if auth.MsgUrl == msgURL { a.Authorizations = append(a.Authorizations[:i], a.Authorizations[i+1:]...) + return } } } -// GetAuthorizedPolicy returns the policy for the given message url. If the message url is not found, - +// GetAuthorizedPolicy returns the policy for the given message url. If the message url is not found, it returns an error. func (a *AuthorizationList) GetAuthorizedPolicy(msgURL string) (PolicyType, error) { for _, auth := range a.Authorizations { if auth.MsgUrl == msgURL { return auth.AuthorizedPolicy, nil } } - // Returning first value of enum, can consider adding a default value of `EmptyPolicy` in the enum. - return PolicyType(0), ErrAuthorizationNotFound + return PolicyType_groupEmpty, ErrAuthorizationNotFound } // Validate checks if the authorization list is valid. It returns an error if the message url is duplicated with different policies. diff --git a/x/authority/types/authorizations_test.go b/x/authority/types/authorizations_test.go index 8bb7ed805a..009e958c15 100644 --- a/x/authority/types/authorizations_test.go +++ b/x/authority/types/authorizations_test.go @@ -176,21 +176,21 @@ func TestAuthorizationList_GetAuthorizations(t *testing.T) { }, }}, getPolicyMsgUrl: "XYZ", - expectedPolicy: types.PolicyType(0), + expectedPolicy: types.PolicyType_groupEmpty, error: types.ErrAuthorizationNotFound, }, { name: "get authorizations fails when msg not found in list", authorizations: types.AuthorizationList{Authorizations: []types.Authorization{}}, getPolicyMsgUrl: "ABC", - expectedPolicy: types.PolicyType(0), + expectedPolicy: types.PolicyType_groupEmpty, error: types.ErrAuthorizationNotFound, }, { name: "get authorizations fails when when queried for empty string", authorizations: types.AuthorizationList{Authorizations: []types.Authorization{}}, getPolicyMsgUrl: "", - expectedPolicy: types.PolicyType(0), + expectedPolicy: types.PolicyType_groupEmpty, error: types.ErrAuthorizationNotFound, }, } @@ -275,10 +275,10 @@ func TestAuthorizationList_Validate(t *testing.T) { func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { tt := []struct { - name string - oldList types.AuthorizationList - removeAuthorization types.Authorization - expectedList types.AuthorizationList + name string + oldList types.AuthorizationList + removeMsgUrl string + expectedList types.AuthorizationList }{ { name: "remove authorization successfully", @@ -292,9 +292,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, - removeAuthorization: types.Authorization{ - MsgUrl: "ABC", - }, + removeMsgUrl: "ABC", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "XYZ", @@ -318,9 +316,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, - removeAuthorization: types.Authorization{ - MsgUrl: "XYZ", - }, + removeMsgUrl: "XYZ", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "ABC", @@ -333,11 +329,9 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { }}, }, { - name: "do not remove anything when trying to remove from an empty list", - oldList: types.AuthorizationList{Authorizations: []types.Authorization{}}, - removeAuthorization: types.Authorization{ - MsgUrl: "XYZ", - }, + name: "do not remove anything when trying to remove from an empty list", + oldList: types.AuthorizationList{Authorizations: []types.Authorization{}}, + removeMsgUrl: "XYZ", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{}}, }, { @@ -348,9 +342,28 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, - removeAuthorization: types.Authorization{ - MsgUrl: "XYZ", - }, + removeMsgUrl: "XYZ", + expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }}, + }, + // The list is invalid, but this test case tries to assert the expected functionality + { + name: "return after removing first occurrence", + oldList: types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }}, + removeMsgUrl: "ABC", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "ABC", @@ -361,7 +374,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { - tc.oldList.RemoveAuthorization(tc.removeAuthorization) + tc.oldList.RemoveAuthorization(tc.removeMsgUrl) require.Equal(t, tc.expectedList, tc.oldList) }) } @@ -407,6 +420,8 @@ func TestDefaultAuthorizationsList(t *testing.T) { sdk.MsgTypeURL(&fungibletypes.MsgUpdateContractBytecode{}), sdk.MsgTypeURL(&fungibletypes.MsgUpdateSystemContract{}), sdk.MsgTypeURL(&observertypes.MsgUpdateObserver{}), + sdk.MsgTypeURL(&types.MsgAddAuthorization{}), + sdk.MsgTypeURL(&types.MsgRemoveAuthorization{}), } defaultList := types.DefaultAuthorizationsList() for _, msgUrl := range OperationalPolicyMessageList { diff --git a/x/authority/types/errors.go b/x/authority/types/errors.go index 88b44b9887..9d9509e9d4 100644 --- a/x/authority/types/errors.go +++ b/x/authority/types/errors.go @@ -3,7 +3,8 @@ package types import errorsmod "cosmossdk.io/errors" var ( - ErrUnauthorized = errorsmod.Register(ModuleName, 1102, "sender not authorized") - ErrInvalidAuthorizationList = errorsmod.Register(ModuleName, 1103, "invalid authorization list") - ErrAuthorizationNotFound = errorsmod.Register(ModuleName, 1104, "authorization not found") + ErrUnauthorized = errorsmod.Register(ModuleName, 1102, "sender not authorized") + ErrInvalidAuthorizationList = errorsmod.Register(ModuleName, 1103, "invalid authorization list") + ErrAuthorizationNotFound = errorsmod.Register(ModuleName, 1104, "authorization not found") + ErrAuthorizationListNotFound = errorsmod.Register(ModuleName, 1105, "authorization list not found") ) diff --git a/x/authority/types/message_add_authorization.go b/x/authority/types/message_add_authorization.go new file mode 100644 index 0000000000..0de3162a78 --- /dev/null +++ b/x/authority/types/message_add_authorization.go @@ -0,0 +1,65 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgAddAuthorization = "AddAuthorization" + +var _ sdk.Msg = &MsgAddAuthorization{} + +func NewMsgAddAuthorization(creator string, msgURL string, authorizedPolicy PolicyType) *MsgAddAuthorization { + return &MsgAddAuthorization{ + Creator: creator, + MsgUrl: msgURL, + AuthorizedPolicy: authorizedPolicy, + } +} + +func (msg *MsgAddAuthorization) Route() string { + return RouterKey +} + +func (msg *MsgAddAuthorization) Type() string { + return TypeMsgAddAuthorization +} + +func (msg *MsgAddAuthorization) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +func (msg *MsgAddAuthorization) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgAddAuthorization) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + // the authorized policy must be valid + if err := msg.AuthorizedPolicy.Validate(); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authorized policy: %s", err.Error()) + } + + // the message URL must be valid + if err := ValidateMsgURL(msg.MsgUrl); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid msg url: %s", err.Error()) + } + + return nil +} + +func ValidateMsgURL(url string) error { + if len(url) == 0 { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "message URL cannot be empty") + } + return nil +} diff --git a/x/authority/types/message_add_authorizations_test.go b/x/authority/types/message_add_authorizations_test.go new file mode 100644 index 0000000000..dcc970adbd --- /dev/null +++ b/x/authority/types/message_add_authorizations_test.go @@ -0,0 +1,130 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgAddAuthorization_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg *types.MsgAddAuthorization + expectErr require.ErrorAssertionFunc + }{ + { + name: "invalid creator address", + msg: types.NewMsgAddAuthorization("invalid", "url", types.PolicyType_groupAdmin), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.ErrorContains(t, err, "invalid creator address") + }, + }, + { + name: "invalid authorized policy", + msg: types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupEmpty), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "invalid authorized policy") + }, + }, + { + name: "invalid msg url", + msg: types.NewMsgAddAuthorization(sample.AccAddress(), "", types.PolicyType_groupAdmin), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "invalid msg url") + }, + }, + { + name: "valid message", + msg: types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin), + expectErr: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.expectErr(t, tt.msg.ValidateBasic()) + }) + } +} + +func TestMsgAddAuthorization_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgAddAuthorization + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgAddAuthorization(signer, "url", types.PolicyType_groupAdmin), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgAddAuthorization("creator", "url", types.PolicyType_groupAdmin), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgAddAuthorization_Type(t *testing.T) { + msg := types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin) + require.Equal(t, types.TypeMsgAddAuthorization, msg.Type()) +} + +func TestMsgAddAuthorization_Route(t *testing.T) { + msg := types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin) + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgAddAuthorization_GetSignBytes(t *testing.T) { + msg := types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin) + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} + +func TestValidateMsgUrl(t *testing.T) { + tests := []struct { + name string + url string + expectErr error + }{ + { + name: "empty url", + url: "", + expectErr: sdkerrors.ErrInvalidRequest, + }, + { + name: "valid url", + url: "/zetachain.zetacore.crosschain.MsgRefundAbortedCCTX", + expectErr: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := types.ValidateMsgURL(tt.url) + require.ErrorIs(t, err, tt.expectErr) + }) + } +} diff --git a/x/authority/types/message_remove_authorization.go b/x/authority/types/message_remove_authorization.go new file mode 100644 index 0000000000..2404282088 --- /dev/null +++ b/x/authority/types/message_remove_authorization.go @@ -0,0 +1,51 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeRemoveAuthorization = "RemoveAuthorization" + +var _ sdk.Msg = &MsgRemoveAuthorization{} + +func NewMsgRemoveAuthorization(creator string, msgURL string) *MsgRemoveAuthorization { + return &MsgRemoveAuthorization{ + Creator: creator, + MsgUrl: msgURL, + } +} + +func (msg *MsgRemoveAuthorization) Route() string { + return RouterKey +} + +func (msg *MsgRemoveAuthorization) Type() string { + return TypeRemoveAuthorization +} + +func (msg *MsgRemoveAuthorization) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +func (msg *MsgRemoveAuthorization) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgRemoveAuthorization) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if err := ValidateMsgURL(msg.MsgUrl); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid msg url: %s", err.Error()) + } + + return nil +} diff --git a/x/authority/types/message_remove_authorizations_test.go b/x/authority/types/message_remove_authorizations_test.go new file mode 100644 index 0000000000..d9e35e45e0 --- /dev/null +++ b/x/authority/types/message_remove_authorizations_test.go @@ -0,0 +1,97 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgRemoveAuthorization_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg *types.MsgRemoveAuthorization + expectErr require.ErrorAssertionFunc + }{ + { + name: "invalid creator address", + msg: types.NewMsgRemoveAuthorization("invalid", "url"), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.ErrorContains(t, err, "invalid creator address") + }, + }, + { + name: "invalid msg url", + msg: types.NewMsgRemoveAuthorization(sample.AccAddress(), ""), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "invalid msg url") + }, + }, + { + name: "valid message", + msg: types.NewMsgRemoveAuthorization(sample.AccAddress(), "url"), + expectErr: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.expectErr(t, tt.msg.ValidateBasic()) + }) + } +} + +func TestMsgRemoveAuthorization_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgRemoveAuthorization + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgRemoveAuthorization(signer, "url"), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgRemoveAuthorization("creator", "url"), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgRemoveAuthorization_Type(t *testing.T) { + msg := types.NewMsgRemoveAuthorization(sample.AccAddress(), "url") + require.Equal(t, types.TypeRemoveAuthorization, msg.Type()) +} + +func TestMsgRemoveAuthorization_Route(t *testing.T) { + msg := types.NewMsgRemoveAuthorization(sample.AccAddress(), "url") + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgRemoveAuthorization_GetSignBytes(t *testing.T) { + msg := types.NewMsgRemoveAuthorization(sample.AccAddress(), "url") + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/authority/types/policies.go b/x/authority/types/policies.go index 28a97594ce..af3642bfd7 100644 --- a/x/authority/types/policies.go +++ b/x/authority/types/policies.go @@ -42,9 +42,8 @@ func (p Policies) Validate() error { return fmt.Errorf("invalid address: %s", err) } - if policy.PolicyType != PolicyType_groupEmergency && policy.PolicyType != PolicyType_groupAdmin && - policy.PolicyType != PolicyType_groupOperational { - return fmt.Errorf("invalid policy type: %s", policy.PolicyType) + if err := policy.PolicyType.Validate(); err != nil { + return err } if policyTypeMap[policy.PolicyType] { diff --git a/x/authority/types/policies.pb.go b/x/authority/types/policies.pb.go index 3b2eda6564..c67621c996 100644 --- a/x/authority/types/policies.pb.go +++ b/x/authority/types/policies.pb.go @@ -31,18 +31,22 @@ const ( PolicyType_groupOperational PolicyType = 1 // non-sensitive protocol parameters PolicyType_groupAdmin PolicyType = 2 + // protocol parameters or moving funds + PolicyType_groupEmpty PolicyType = 3 ) var PolicyType_name = map[int32]string{ 0: "groupEmergency", 1: "groupOperational", 2: "groupAdmin", + 3: "groupEmpty", } var PolicyType_value = map[string]int32{ "groupEmergency": 0, "groupOperational": 1, "groupAdmin": 2, + "groupEmpty": 3, } func (x PolicyType) String() string { @@ -161,26 +165,27 @@ func init() { } var fileDescriptor_afa9e3e7b996ef74 = []byte{ - // 303 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xae, 0x4a, 0x2d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x13, 0x4b, 0x4b, 0x32, - 0xf2, 0x8b, 0x32, 0x4b, 0x2a, 0xf5, 0x0b, 0xf2, 0x73, 0x32, 0x93, 0x33, 0x53, 0x8b, 0xf5, 0x0a, - 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x64, 0xe0, 0x8a, 0xf5, 0x60, 0x8a, 0xf5, 0xe0, 0x8a, 0xa5, 0x44, - 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x0a, 0xf5, 0x41, 0x2c, 0x88, 0x1e, 0xa5, 0x5c, 0x2e, 0xb6, 0x00, - 0x90, 0x29, 0x95, 0x42, 0x9e, 0x5c, 0xdc, 0x60, 0xf3, 0x2a, 0xe3, 0x4b, 0x2a, 0x0b, 0x52, 0x25, - 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0x34, 0xf4, 0xf0, 0x99, 0xa9, 0x07, 0xd1, 0x1a, 0x52, 0x59, - 0x90, 0x1a, 0xc4, 0x55, 0x00, 0x67, 0x0b, 0x49, 0x70, 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, - 0x17, 0x4b, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x06, 0xc1, 0xb8, 0x4a, 0x6e, 0x5c, 0x1c, 0x01, 0x50, - 0x47, 0x0b, 0x59, 0x71, 0xb1, 0x66, 0x96, 0xa4, 0xe6, 0x16, 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0x70, - 0x1b, 0xa9, 0x10, 0x63, 0x55, 0x10, 0x44, 0x8b, 0x96, 0x0f, 0x17, 0x17, 0xc2, 0x6e, 0x21, 0x21, - 0x2e, 0xbe, 0xf4, 0xa2, 0xfc, 0xd2, 0x02, 0xd7, 0xdc, 0xd4, 0xa2, 0xf4, 0xd4, 0xbc, 0xe4, 0x4a, - 0x01, 0x06, 0x21, 0x11, 0x2e, 0x01, 0xb0, 0x98, 0x7f, 0x41, 0x6a, 0x51, 0x62, 0x49, 0x66, 0x7e, - 0x5e, 0x62, 0x8e, 0x00, 0xa3, 0x10, 0x1f, 0x17, 0x17, 0x58, 0xd4, 0x31, 0x25, 0x37, 0x33, 0x4f, - 0x80, 0x49, 0x8a, 0x65, 0xc5, 0x12, 0x39, 0x46, 0x27, 0xaf, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, - 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, - 0x3c, 0x96, 0x63, 0x88, 0x32, 0x48, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0x05, - 0x47, 0x80, 0x2e, 0x5a, 0x5c, 0x54, 0x20, 0xc5, 0x06, 0x28, 0xd8, 0x8a, 0x93, 0xd8, 0xc0, 0xe1, - 0x6a, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x91, 0xe5, 0xab, 0xba, 0x01, 0x00, 0x00, + // 310 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x51, 0xc1, 0x4a, 0x03, 0x31, + 0x14, 0xdc, 0xb4, 0x5a, 0xf5, 0x15, 0xca, 0x12, 0x7a, 0x58, 0x8a, 0x84, 0x52, 0x3c, 0x2c, 0x8a, + 0x59, 0xa9, 0x37, 0x6f, 0x0a, 0x15, 0xf4, 0x62, 0x29, 0x9e, 0x44, 0x90, 0x74, 0x1b, 0xb6, 0x81, + 0x66, 0x13, 0xb2, 0x29, 0x18, 0xbf, 0xc2, 0x8f, 0xf0, 0xe0, 0xa7, 0x78, 0xec, 0xd1, 0xa3, 0xb4, + 0x3f, 0x22, 0xcd, 0xda, 0x55, 0x3c, 0x88, 0xb7, 0x79, 0x8f, 0x99, 0x79, 0x8f, 0x19, 0x38, 0x7a, + 0xe2, 0x96, 0xa5, 0x53, 0x26, 0xf2, 0xc4, 0x23, 0x65, 0x78, 0xc2, 0xe6, 0x76, 0xaa, 0x8c, 0xb0, + 0x2e, 0xd1, 0x6a, 0x26, 0x52, 0xc1, 0x0b, 0xaa, 0x8d, 0xb2, 0x0a, 0xef, 0x57, 0x64, 0xba, 0x21, + 0xd3, 0x8a, 0xdc, 0x69, 0x67, 0x2a, 0x53, 0x9e, 0x98, 0xac, 0x51, 0xa9, 0xe9, 0x49, 0x68, 0x0c, + 0xd7, 0x2e, 0x0e, 0x5f, 0x41, 0xd3, 0xfb, 0xb9, 0x07, 0xeb, 0x34, 0x8f, 0x50, 0x17, 0xc5, 0xad, + 0x7e, 0x4c, 0xff, 0xf2, 0xa4, 0xa5, 0xf4, 0xd6, 0x69, 0x3e, 0x02, 0x5d, 0x61, 0x1c, 0xc1, 0x0e, + 0x9b, 0x4c, 0x0c, 0x2f, 0x8a, 0xa8, 0xd6, 0x45, 0xf1, 0xde, 0x68, 0x33, 0xf6, 0x2e, 0x61, 0x77, + 0xf8, 0xf5, 0x34, 0x3e, 0x83, 0x6d, 0x61, 0xb9, 0x2c, 0x22, 0xd4, 0xad, 0xc7, 0xcd, 0xfe, 0xc1, + 0x7f, 0x4e, 0x8d, 0x4a, 0xc9, 0xe1, 0x3d, 0xc0, 0xf7, 0x6d, 0x8c, 0xa1, 0x95, 0x19, 0x35, 0xd7, + 0x03, 0xc9, 0x4d, 0xc6, 0xf3, 0xd4, 0x85, 0x01, 0x6e, 0x43, 0xe8, 0x77, 0x37, 0x9a, 0x1b, 0x66, + 0x85, 0xca, 0xd9, 0x2c, 0x44, 0xb8, 0x05, 0xe0, 0xb7, 0xe7, 0x13, 0x29, 0xf2, 0xb0, 0x56, 0xcd, + 0x03, 0xa9, 0xad, 0x0b, 0xeb, 0x9d, 0xad, 0xd7, 0x17, 0x82, 0x2e, 0xae, 0xdf, 0x96, 0x04, 0x2d, + 0x96, 0x04, 0x7d, 0x2c, 0x09, 0x7a, 0x5e, 0x91, 0x60, 0xb1, 0x22, 0xc1, 0xfb, 0x8a, 0x04, 0x77, + 0x27, 0x99, 0xb0, 0xd3, 0xf9, 0x98, 0xa6, 0x4a, 0xfa, 0x42, 0x8e, 0x7f, 0x75, 0xf3, 0xf8, 0xa3, + 0x9d, 0x75, 0x8c, 0xc5, 0xb8, 0xe1, 0x73, 0x3e, 0xfd, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x37, 0x5d, + 0x49, 0x63, 0xca, 0x01, 0x00, 0x00, } func (m *Policy) Marshal() (dAtA []byte, err error) { diff --git a/x/authority/types/policy_type.go b/x/authority/types/policy_type.go new file mode 100644 index 0000000000..c3593e7fae --- /dev/null +++ b/x/authority/types/policy_type.go @@ -0,0 +1,13 @@ +package types + +import "fmt" + +// Validate PolicyType validates the policy type. +// Valid policy types are groupEmergency, groupOperational, and groupAdmin. +func (p PolicyType) Validate() error { + if p != PolicyType_groupEmergency && p != PolicyType_groupAdmin && + p != PolicyType_groupOperational { + return fmt.Errorf("invalid policy type: %s", p) + } + return nil +} diff --git a/x/authority/types/policy_type_test.go b/x/authority/types/policy_type_test.go new file mode 100644 index 0000000000..c6778c9200 --- /dev/null +++ b/x/authority/types/policy_type_test.go @@ -0,0 +1,58 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestPolicyType_Validate(t *testing.T) { + tests := []struct { + name string + policyType types.PolicyType + wantErr bool + }{ + { + name: "valid groupEmergency", + policyType: types.PolicyType_groupEmergency, + wantErr: false, + }, + { + name: "valid groupOperational", + policyType: types.PolicyType_groupOperational, + wantErr: false, + }, + { + name: "valid groupAdmin", + policyType: types.PolicyType_groupAdmin, + wantErr: false, + }, + { + name: "invalid policy type", + policyType: types.PolicyType(20), + wantErr: true, + }, + { + name: "invalid policy type more than max length", + policyType: types.PolicyType(len(types.PolicyType_name) + 1), + wantErr: true, + }, + { + name: "empty policy type", + policyType: types.PolicyType_groupEmpty, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.policyType.Validate() + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/authority/types/tx.pb.go b/x/authority/types/tx.pb.go index ac5c04416b..928353417f 100644 --- a/x/authority/types/tx.pb.go +++ b/x/authority/types/tx.pb.go @@ -28,6 +28,198 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// MsgAddAuthorization defines the MsgAddAuthorization service. +// Adds an authorization to the chain. If the authorization already exists, it +// will be updated. +type MsgAddAuthorization struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + MsgUrl string `protobuf:"bytes,2,opt,name=msg_url,json=msgUrl,proto3" json:"msg_url,omitempty"` + AuthorizedPolicy PolicyType `protobuf:"varint,3,opt,name=authorized_policy,json=authorizedPolicy,proto3,enum=zetachain.zetacore.authority.PolicyType" json:"authorized_policy,omitempty"` +} + +func (m *MsgAddAuthorization) Reset() { *m = MsgAddAuthorization{} } +func (m *MsgAddAuthorization) String() string { return proto.CompactTextString(m) } +func (*MsgAddAuthorization) ProtoMessage() {} +func (*MsgAddAuthorization) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{0} +} +func (m *MsgAddAuthorization) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddAuthorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddAuthorization.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddAuthorization) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddAuthorization.Merge(m, src) +} +func (m *MsgAddAuthorization) XXX_Size() int { + return m.Size() +} +func (m *MsgAddAuthorization) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddAuthorization.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddAuthorization proto.InternalMessageInfo + +func (m *MsgAddAuthorization) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgAddAuthorization) GetMsgUrl() string { + if m != nil { + return m.MsgUrl + } + return "" +} + +func (m *MsgAddAuthorization) GetAuthorizedPolicy() PolicyType { + if m != nil { + return m.AuthorizedPolicy + } + return PolicyType_groupEmergency +} + +// MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. +type MsgAddAuthorizationResponse struct { +} + +func (m *MsgAddAuthorizationResponse) Reset() { *m = MsgAddAuthorizationResponse{} } +func (m *MsgAddAuthorizationResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAddAuthorizationResponse) ProtoMessage() {} +func (*MsgAddAuthorizationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{1} +} +func (m *MsgAddAuthorizationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddAuthorizationResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddAuthorizationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddAuthorizationResponse.Merge(m, src) +} +func (m *MsgAddAuthorizationResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAddAuthorizationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddAuthorizationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddAuthorizationResponse proto.InternalMessageInfo + +// MsgRemoveAuthorization defines the MsgRemoveAuthorization service. +// Removes an authorization from the chain. +type MsgRemoveAuthorization struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + MsgUrl string `protobuf:"bytes,2,opt,name=msg_url,json=msgUrl,proto3" json:"msg_url,omitempty"` +} + +func (m *MsgRemoveAuthorization) Reset() { *m = MsgRemoveAuthorization{} } +func (m *MsgRemoveAuthorization) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveAuthorization) ProtoMessage() {} +func (*MsgRemoveAuthorization) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{2} +} +func (m *MsgRemoveAuthorization) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveAuthorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveAuthorization.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveAuthorization) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveAuthorization.Merge(m, src) +} +func (m *MsgRemoveAuthorization) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveAuthorization) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveAuthorization.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveAuthorization proto.InternalMessageInfo + +func (m *MsgRemoveAuthorization) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgRemoveAuthorization) GetMsgUrl() string { + if m != nil { + return m.MsgUrl + } + return "" +} + +// MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse +// service. +type MsgRemoveAuthorizationResponse struct { +} + +func (m *MsgRemoveAuthorizationResponse) Reset() { *m = MsgRemoveAuthorizationResponse{} } +func (m *MsgRemoveAuthorizationResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveAuthorizationResponse) ProtoMessage() {} +func (*MsgRemoveAuthorizationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{3} +} +func (m *MsgRemoveAuthorizationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveAuthorizationResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveAuthorizationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveAuthorizationResponse.Merge(m, src) +} +func (m *MsgRemoveAuthorizationResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveAuthorizationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveAuthorizationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveAuthorizationResponse proto.InternalMessageInfo + // MsgUpdatePolicies defines the MsgUpdatePolicies service. type MsgUpdatePolicies struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` @@ -38,7 +230,7 @@ func (m *MsgUpdatePolicies) Reset() { *m = MsgUpdatePolicies{} } func (m *MsgUpdatePolicies) String() string { return proto.CompactTextString(m) } func (*MsgUpdatePolicies) ProtoMessage() {} func (*MsgUpdatePolicies) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{0} + return fileDescriptor_42e081863c477116, []int{4} } func (m *MsgUpdatePolicies) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -89,7 +281,7 @@ func (m *MsgUpdatePoliciesResponse) Reset() { *m = MsgUpdatePoliciesResp func (m *MsgUpdatePoliciesResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdatePoliciesResponse) ProtoMessage() {} func (*MsgUpdatePoliciesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{1} + return fileDescriptor_42e081863c477116, []int{5} } func (m *MsgUpdatePoliciesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -128,7 +320,7 @@ func (m *MsgUpdateChainInfo) Reset() { *m = MsgUpdateChainInfo{} } func (m *MsgUpdateChainInfo) String() string { return proto.CompactTextString(m) } func (*MsgUpdateChainInfo) ProtoMessage() {} func (*MsgUpdateChainInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{2} + return fileDescriptor_42e081863c477116, []int{6} } func (m *MsgUpdateChainInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -179,7 +371,7 @@ func (m *MsgUpdateChainInfoResponse) Reset() { *m = MsgUpdateChainInfoRe func (m *MsgUpdateChainInfoResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateChainInfoResponse) ProtoMessage() {} func (*MsgUpdateChainInfoResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{3} + return fileDescriptor_42e081863c477116, []int{7} } func (m *MsgUpdateChainInfoResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -209,6 +401,10 @@ func (m *MsgUpdateChainInfoResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateChainInfoResponse proto.InternalMessageInfo func init() { + proto.RegisterType((*MsgAddAuthorization)(nil), "zetachain.zetacore.authority.MsgAddAuthorization") + proto.RegisterType((*MsgAddAuthorizationResponse)(nil), "zetachain.zetacore.authority.MsgAddAuthorizationResponse") + proto.RegisterType((*MsgRemoveAuthorization)(nil), "zetachain.zetacore.authority.MsgRemoveAuthorization") + proto.RegisterType((*MsgRemoveAuthorizationResponse)(nil), "zetachain.zetacore.authority.MsgRemoveAuthorizationResponse") proto.RegisterType((*MsgUpdatePolicies)(nil), "zetachain.zetacore.authority.MsgUpdatePolicies") proto.RegisterType((*MsgUpdatePoliciesResponse)(nil), "zetachain.zetacore.authority.MsgUpdatePoliciesResponse") proto.RegisterType((*MsgUpdateChainInfo)(nil), "zetachain.zetacore.authority.MsgUpdateChainInfo") @@ -220,29 +416,38 @@ func init() { } var fileDescriptor_42e081863c477116 = []byte{ - // 350 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xad, 0x4a, 0x2d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x13, 0x4b, 0x4b, 0x32, - 0xf2, 0x8b, 0x32, 0x4b, 0x2a, 0xf5, 0x4b, 0x2a, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x64, - 0xe0, 0xca, 0xf4, 0x60, 0xca, 0xf4, 0xe0, 0xca, 0xa4, 0xb4, 0xf1, 0x1a, 0x52, 0x90, 0x9f, 0x93, - 0x99, 0x9c, 0x99, 0x5a, 0x0c, 0x31, 0x4a, 0x4a, 0x17, 0xaf, 0x62, 0xb0, 0x44, 0x7c, 0x66, 0x5e, - 0x5a, 0x3e, 0x54, 0xb9, 0x01, 0x5e, 0xe5, 0x50, 0x56, 0x55, 0x62, 0x49, 0x66, 0x7e, 0x1e, 0x54, - 0x87, 0x48, 0x7a, 0x7e, 0x7a, 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x44, 0x95, 0xca, 0xb9, 0x04, - 0x7d, 0x8b, 0xd3, 0x43, 0x0b, 0x52, 0x12, 0x4b, 0x52, 0x03, 0xa0, 0x2e, 0x12, 0x92, 0xe0, 0x62, - 0x4f, 0x2e, 0x4a, 0x4d, 0x2c, 0xc9, 0x2f, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0x71, - 0x85, 0x3c, 0xb8, 0x38, 0x60, 0xee, 0x96, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd3, 0xc3, - 0x17, 0x06, 0x7a, 0x30, 0x33, 0x9d, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0xeb, 0x56, 0x92, - 0xe6, 0x92, 0xc4, 0xb0, 0x38, 0x28, 0xb5, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0xa9, 0x86, 0x4b, - 0x08, 0x2e, 0xe9, 0x0c, 0x32, 0xda, 0x33, 0x2f, 0x2d, 0x1f, 0x8f, 0xb3, 0x7c, 0xb8, 0xb8, 0x10, - 0x21, 0x04, 0x75, 0x98, 0x3a, 0x7e, 0x87, 0xc1, 0x8d, 0x85, 0xba, 0x8c, 0x33, 0x19, 0x26, 0xa0, - 0x24, 0xc3, 0x25, 0x85, 0x69, 0x3b, 0xcc, 0x6d, 0x46, 0x0d, 0x4c, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, - 0x42, 0x55, 0x5c, 0x7c, 0x68, 0xc1, 0xa6, 0x8f, 0xdf, 0x46, 0x0c, 0xef, 0x4a, 0x99, 0x93, 0xa8, - 0x01, 0xe6, 0x06, 0xa1, 0x5a, 0x2e, 0x7e, 0xf4, 0xc0, 0x31, 0x20, 0xd2, 0x2c, 0xb8, 0x0e, 0x29, - 0x0b, 0x52, 0x75, 0xc0, 0xac, 0x77, 0xf2, 0x3a, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, - 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, - 0x86, 0x28, 0x83, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x70, 0xba, 0xd4, - 0x45, 0x4b, 0xa2, 0x15, 0xc8, 0xb9, 0xa8, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x9c, 0x0e, 0x8d, - 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe8, 0xeb, 0xa6, 0x40, 0x72, 0x03, 0x00, 0x00, + // 487 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4f, 0x6f, 0xd3, 0x30, + 0x14, 0xaf, 0xd9, 0xb4, 0xb1, 0x87, 0x34, 0xb6, 0x0c, 0x41, 0xc9, 0x46, 0xa8, 0x22, 0x01, 0x95, + 0xd0, 0x92, 0x52, 0x90, 0x00, 0x89, 0xcb, 0xc6, 0x85, 0x7f, 0x95, 0xa6, 0x88, 0x5e, 0xb8, 0x54, + 0x59, 0xea, 0xb9, 0x96, 0xda, 0x38, 0x8a, 0x5d, 0x58, 0x2b, 0x90, 0xb8, 0x72, 0x82, 0x6f, 0xc0, + 0xd7, 0xd9, 0x71, 0x47, 0x4e, 0x08, 0xb5, 0x5f, 0x04, 0xcd, 0x8d, 0xbd, 0x29, 0x89, 0xbc, 0x16, + 0x6e, 0x2f, 0xf6, 0xef, 0x9f, 0x9f, 0xe3, 0x07, 0xf7, 0xc6, 0x58, 0x84, 0x51, 0x2f, 0xa4, 0xb1, + 0x2f, 0x2b, 0x96, 0x62, 0x3f, 0x1c, 0x8a, 0x1e, 0x4b, 0xa9, 0x18, 0xf9, 0xe2, 0xd8, 0x4b, 0x52, + 0x26, 0x98, 0xb5, 0xa3, 0x61, 0x9e, 0x82, 0x79, 0x1a, 0x66, 0x3f, 0x34, 0x8a, 0x24, 0xac, 0x4f, + 0x23, 0x8a, 0xf9, 0x4c, 0xca, 0xde, 0x35, 0x82, 0xe5, 0x46, 0x87, 0xc6, 0x47, 0x2c, 0x83, 0x37, + 0x8c, 0xf0, 0xac, 0x1a, 0x87, 0x82, 0xb2, 0x38, 0x63, 0xdc, 0x20, 0x8c, 0x30, 0x59, 0xfa, 0x67, + 0xd5, 0x6c, 0xd5, 0xfd, 0x89, 0x60, 0xab, 0xc5, 0xc9, 0x5e, 0xb7, 0xbb, 0x77, 0x91, 0x63, 0x55, + 0x61, 0x35, 0x4a, 0x71, 0x28, 0x58, 0x5a, 0x45, 0x35, 0x54, 0x5f, 0x0b, 0xd4, 0xa7, 0x75, 0x0b, + 0x56, 0x07, 0x9c, 0x74, 0x86, 0x69, 0xbf, 0x7a, 0x45, 0xee, 0xac, 0x0c, 0x38, 0x69, 0xa7, 0x7d, + 0xab, 0x0d, 0x9b, 0xca, 0x17, 0x77, 0x3b, 0xf2, 0x78, 0xa3, 0xea, 0x52, 0x0d, 0xd5, 0xd7, 0x9b, + 0x75, 0xcf, 0xd4, 0x28, 0xef, 0x40, 0x62, 0xdf, 0x8f, 0x12, 0x1c, 0x6c, 0x9c, 0x4b, 0xcc, 0x56, + 0xdd, 0x3b, 0xb0, 0x5d, 0x12, 0x30, 0xc0, 0x3c, 0x61, 0x31, 0xc7, 0xee, 0x5b, 0xb8, 0xd9, 0xe2, + 0x24, 0xc0, 0x03, 0xf6, 0x11, 0xff, 0xef, 0x11, 0xdc, 0x1a, 0x38, 0xe5, 0x62, 0xda, 0xee, 0x13, + 0x6c, 0xb6, 0x38, 0x69, 0x27, 0xdd, 0x50, 0xe0, 0x83, 0xec, 0x06, 0x0d, 0x4e, 0xaf, 0xe0, 0xaa, + 0xba, 0x67, 0x69, 0x75, 0xad, 0x79, 0x7f, 0x8e, 0x56, 0x50, 0xcc, 0xf7, 0x97, 0x4f, 0x7e, 0xdf, + 0xad, 0x04, 0x9a, 0xed, 0x6e, 0xc3, 0xed, 0x82, 0xb1, 0x4e, 0xf5, 0x19, 0x2c, 0xbd, 0xf9, 0xf2, + 0x4c, 0xfa, 0x75, 0x7c, 0xc4, 0x0c, 0xb1, 0xde, 0x01, 0x9c, 0xff, 0x51, 0x59, 0xb0, 0x07, 0xe6, + 0x60, 0x5a, 0x36, 0x4b, 0xb6, 0x16, 0xa9, 0x05, 0x77, 0x07, 0xec, 0xa2, 0xbb, 0xca, 0xd6, 0xfc, + 0xbe, 0x0c, 0x4b, 0x2d, 0x4e, 0xac, 0x31, 0xac, 0xe7, 0xda, 0xe6, 0x9b, 0x1d, 0x0b, 0xc7, 0xb5, + 0x9f, 0x2e, 0x48, 0x50, 0x19, 0xac, 0x2f, 0x70, 0x3d, 0xdf, 0x9c, 0xc6, 0x9c, 0x5a, 0x9a, 0x61, + 0x3f, 0x5b, 0x94, 0xa1, 0xed, 0xbf, 0x22, 0xd8, 0x28, 0xbc, 0xb0, 0x47, 0x97, 0xca, 0xe5, 0x29, + 0xf6, 0xf3, 0x85, 0x29, 0x3a, 0xc2, 0x37, 0x04, 0x5b, 0x65, 0x8f, 0xe4, 0xc9, 0xa5, 0x92, 0x25, + 0x2c, 0xfb, 0xc5, 0xbf, 0xb0, 0x54, 0x96, 0xfd, 0x37, 0x27, 0x13, 0x07, 0x9d, 0x4e, 0x1c, 0xf4, + 0x67, 0xe2, 0xa0, 0x1f, 0x53, 0xa7, 0x72, 0x3a, 0x75, 0x2a, 0xbf, 0xa6, 0x4e, 0xe5, 0x43, 0x83, + 0x50, 0xd1, 0x1b, 0x1e, 0x7a, 0x11, 0x1b, 0xc8, 0xb1, 0xb6, 0x9b, 0x9b, 0x70, 0xc7, 0x17, 0x87, + 0xf0, 0x28, 0xc1, 0xfc, 0x70, 0x45, 0x8e, 0xb1, 0xc7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x33, + 0xb2, 0x7c, 0x5f, 0xb1, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -259,6 +464,8 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { UpdatePolicies(ctx context.Context, in *MsgUpdatePolicies, opts ...grpc.CallOption) (*MsgUpdatePoliciesResponse, error) UpdateChainInfo(ctx context.Context, in *MsgUpdateChainInfo, opts ...grpc.CallOption) (*MsgUpdateChainInfoResponse, error) + AddAuthorization(ctx context.Context, in *MsgAddAuthorization, opts ...grpc.CallOption) (*MsgAddAuthorizationResponse, error) + RemoveAuthorization(ctx context.Context, in *MsgRemoveAuthorization, opts ...grpc.CallOption) (*MsgRemoveAuthorizationResponse, error) } type msgClient struct { @@ -287,10 +494,30 @@ func (c *msgClient) UpdateChainInfo(ctx context.Context, in *MsgUpdateChainInfo, return out, nil } +func (c *msgClient) AddAuthorization(ctx context.Context, in *MsgAddAuthorization, opts ...grpc.CallOption) (*MsgAddAuthorizationResponse, error) { + out := new(MsgAddAuthorizationResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.authority.Msg/AddAuthorization", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RemoveAuthorization(ctx context.Context, in *MsgRemoveAuthorization, opts ...grpc.CallOption) (*MsgRemoveAuthorizationResponse, error) { + out := new(MsgRemoveAuthorizationResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.authority.Msg/RemoveAuthorization", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { UpdatePolicies(context.Context, *MsgUpdatePolicies) (*MsgUpdatePoliciesResponse, error) UpdateChainInfo(context.Context, *MsgUpdateChainInfo) (*MsgUpdateChainInfoResponse, error) + AddAuthorization(context.Context, *MsgAddAuthorization) (*MsgAddAuthorizationResponse, error) + RemoveAuthorization(context.Context, *MsgRemoveAuthorization) (*MsgRemoveAuthorizationResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -303,6 +530,12 @@ func (*UnimplementedMsgServer) UpdatePolicies(ctx context.Context, req *MsgUpdat func (*UnimplementedMsgServer) UpdateChainInfo(ctx context.Context, req *MsgUpdateChainInfo) (*MsgUpdateChainInfoResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateChainInfo not implemented") } +func (*UnimplementedMsgServer) AddAuthorization(ctx context.Context, req *MsgAddAuthorization) (*MsgAddAuthorizationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddAuthorization not implemented") +} +func (*UnimplementedMsgServer) RemoveAuthorization(ctx context.Context, req *MsgRemoveAuthorization) (*MsgRemoveAuthorizationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RemoveAuthorization not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -344,6 +577,42 @@ func _Msg_UpdateChainInfo_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Msg_AddAuthorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAddAuthorization) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).AddAuthorization(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.authority.Msg/AddAuthorization", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).AddAuthorization(ctx, req.(*MsgAddAuthorization)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RemoveAuthorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRemoveAuthorization) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RemoveAuthorization(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.authority.Msg/RemoveAuthorization", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RemoveAuthorization(ctx, req.(*MsgRemoveAuthorization)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "zetachain.zetacore.authority.Msg", HandlerType: (*MsgServer)(nil), @@ -356,12 +625,20 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateChainInfo", Handler: _Msg_UpdateChainInfo_Handler, }, + { + MethodName: "AddAuthorization", + Handler: _Msg_AddAuthorization_Handler, + }, + { + MethodName: "RemoveAuthorization", + Handler: _Msg_RemoveAuthorization_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "zetachain/zetacore/authority/tx.proto", } -func (m *MsgUpdatePolicies) Marshal() (dAtA []byte, err error) { +func (m *MsgAddAuthorization) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -371,26 +648,28 @@ func (m *MsgUpdatePolicies) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdatePolicies) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgAddAuthorization) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdatePolicies) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgAddAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - { - size, err := m.Policies.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + if m.AuthorizedPolicy != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.AuthorizedPolicy)) + i-- + dAtA[i] = 0x18 + } + if len(m.MsgUrl) > 0 { + i -= len(m.MsgUrl) + copy(dAtA[i:], m.MsgUrl) + i = encodeVarintTx(dAtA, i, uint64(len(m.MsgUrl))) + i-- + dAtA[i] = 0x12 } - i-- - dAtA[i] = 0x12 if len(m.Creator) > 0 { i -= len(m.Creator) copy(dAtA[i:], m.Creator) @@ -401,7 +680,7 @@ func (m *MsgUpdatePolicies) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgUpdatePoliciesResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgAddAuthorizationResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -411,12 +690,12 @@ func (m *MsgUpdatePoliciesResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdatePoliciesResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgAddAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdatePoliciesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgAddAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -424,7 +703,7 @@ func (m *MsgUpdatePoliciesResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *MsgUpdateChainInfo) Marshal() (dAtA []byte, err error) { +func (m *MsgRemoveAuthorization) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -434,18 +713,78 @@ func (m *MsgUpdateChainInfo) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateChainInfo) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgRemoveAuthorization) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgRemoveAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.MsgUrl) > 0 { + i -= len(m.MsgUrl) + copy(dAtA[i:], m.MsgUrl) + i = encodeVarintTx(dAtA, i, uint64(len(m.MsgUrl))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRemoveAuthorizationResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRemoveAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdatePolicies) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdatePolicies) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdatePolicies) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l { - size, err := m.ChainInfo.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Policies.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -464,7 +803,7 @@ func (m *MsgUpdateChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgUpdateChainInfoResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgUpdatePoliciesResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -474,12 +813,12 @@ func (m *MsgUpdateChainInfoResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateChainInfoResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgUpdatePoliciesResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateChainInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgUpdatePoliciesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -487,17 +826,135 @@ func (m *MsgUpdateChainInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } -func encodeVarintTx(dAtA []byte, offset int, v uint64) int { - offset -= sovTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ +func (m *MsgUpdateChainInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateChainInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ChainInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateChainInfoResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateChainInfoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateChainInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ } dAtA[offset] = uint8(v) return base } +func (m *MsgAddAuthorization) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.MsgUrl) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.AuthorizedPolicy != 0 { + n += 1 + sovTx(uint64(m.AuthorizedPolicy)) + } + return n +} + +func (m *MsgAddAuthorizationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRemoveAuthorization) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.MsgUrl) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRemoveAuthorizationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *MsgUpdatePolicies) Size() (n int) { if m == nil { return 0 @@ -552,6 +1009,353 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *MsgAddAuthorization) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddAuthorization: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgUrl", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MsgUrl = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AuthorizedPolicy", wireType) + } + m.AuthorizedPolicy = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AuthorizedPolicy |= PolicyType(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAddAuthorizationResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddAuthorizationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddAuthorizationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveAuthorization) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveAuthorization: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgUrl", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MsgUrl = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveAuthorizationResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveAuthorizationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveAuthorizationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *MsgUpdatePolicies) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/crosschain/keeper/evm_hooks_test.go b/x/crosschain/keeper/evm_hooks_test.go index 3ec4b49e65..80f8c3b28b 100644 --- a/x/crosschain/keeper/evm_hooks_test.go +++ b/x/crosschain/keeper/evm_hooks_test.go @@ -470,7 +470,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) amount, ok := sdkmath.NewIntFromString("20000000000000000000000") @@ -516,7 +516,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { chainID := chain.ChainId setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) event, err := crosschainkeeper.ParseZetaSentEvent( @@ -538,7 +538,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { chain := chains.Ethereum SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) amount, ok := sdkmath.NewIntFromString("20000000000000000000000") @@ -570,7 +570,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { chainID := chain.ChainId setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) amount, ok := sdkmath.NewIntFromString("20000000000000000000000") @@ -634,7 +634,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) zk.ObserverKeeper.SetChainNonces(ctx, observertypes.ChainNonces{ @@ -699,7 +699,7 @@ func TestKeeper_ProcessLogs(t *testing.T) { chainID := chain.ChainId setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) amount, ok := sdkmath.NewIntFromString("20000000000000000000000")