diff --git a/x/axelarcork/keeper/keeper_test.go b/x/axelarcork/keeper/keeper_test.go index b27dd2d5..232f1a51 100644 --- a/x/axelarcork/keeper/keeper_test.go +++ b/x/axelarcork/keeper/keeper_test.go @@ -293,3 +293,40 @@ func (suite *KeeperTestSuite) TestAxelarCorkContractNonces() { {chain2, address2, 2}, }, data) } + +func (suite *KeeperTestSuite) TestAxelarProxyArgsEncoding() { + require := suite.Require() + + address := "0x0000000000000000000000000000000000000000" + cellars := []string{sampleCellarHex, "0x1111111111111111111111111111111111111111"} + + _, err := types.EncodeLogicCallArgs(address, 1, 100000000, []byte("testcall")) + require.NoError(err) + _, err = types.EncodeUpgradeArgs(address, cellars) + require.NoError(err) +} + +// TestAxelarProxyUpgradeData tests the upgrade data set, get, and delete functions +func (suite *KeeperTestSuite) TestAxelarProxyUpgradeData() { + ctx, axelarcorkKeeper := suite.ctx, suite.axelarcorkKeeper + require := suite.Require() + + chainID := uint64(TestEVMChainID) + address := "0x0000000000000000000000000000000000000000" + cellars := []string{sampleCellarHex, "0x1111111111111111111111111111111111111111"} + payload, err := types.EncodeUpgradeArgs(address, cellars) + require.NoError(err) + upgradeData := types.AxelarUpgradeData{ + Payload: payload, + ExecutableHeightThreshold: 10000000, + } + + axelarcorkKeeper.SetAxelarProxyUpgradeData(ctx, chainID, upgradeData) + actualUpgradeData, found := axelarcorkKeeper.GetAxelarProxyUpgradeData(ctx, chainID) + require.True(found) + require.Equal(upgradeData, actualUpgradeData) + + axelarcorkKeeper.DeleteAxelarProxyUpgradeData(ctx, chainID) + _, found = axelarcorkKeeper.GetAxelarProxyUpgradeData(ctx, chainID) + require.False(found) +} diff --git a/x/axelarcork/keeper/msg_server.go b/x/axelarcork/keeper/msg_server.go index 9f3b9d93..94200570 100644 --- a/x/axelarcork/keeper/msg_server.go +++ b/x/axelarcork/keeper/msg_server.go @@ -81,7 +81,7 @@ func (k Keeper) RelayCork(c context.Context, msg *types.MsgRelayAxelarCorkReques } nonce := k.IncrementAxelarContractCallNonce(ctx, msg.ChainId, cork.TargetContractAddress) - payload, err := types.EncodeExecuteArgs(msg.TargetContractAddress, nonce, cork.Deadline, cork.EncodedContractCall) + payload, err := types.EncodeLogicCallArgs(msg.TargetContractAddress, nonce, cork.Deadline, cork.EncodedContractCall) if err != nil { return nil, err } diff --git a/x/axelarcork/types/axelar_proxy.go b/x/axelarcork/types/axelar_proxy.go index 2572b163..2398dead 100644 --- a/x/axelarcork/types/axelar_proxy.go +++ b/x/axelarcork/types/axelar_proxy.go @@ -4,6 +4,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" ) var ( @@ -14,27 +15,30 @@ var ( HourInBlocks = uint64((60 * 60) / 12) DefaultExecutableHeightThreshold = 72 * HourInBlocks -) -type UpgradeData struct { - Payload []byte - ExecutionThresholdHeight uint64 -} + LogicCallMsgID = big.NewInt(0) + UpgradeMsgID = big.NewInt(1) +) -func EncodeExecuteArgs(targetContract string, nonce uint64, deadline uint64, callData []byte) ([]byte, error) { +func EncodeLogicCallArgs(targetContract string, nonce uint64, deadline uint64, callData []byte) ([]byte, error) { return abi.Arguments{ {Type: Uint256}, {Type: Address}, {Type: Uint256}, {Type: Uint256}, {Type: Bytes}, - }.Pack(big.NewInt(0), targetContract, big.NewInt(int64(nonce)), big.NewInt(int64(deadline)), callData) + }.Pack(LogicCallMsgID, common.HexToAddress(targetContract), big.NewInt(int64(nonce)), big.NewInt(int64(deadline)), callData) } func EncodeUpgradeArgs(newAxelarProxy string, targets []string) ([]byte, error) { + targetAddrs := []common.Address{} + for _, target := range targets { + targetAddrs = append(targetAddrs, common.HexToAddress(target)) + } + return abi.Arguments{ {Type: Uint256}, {Type: Address}, {Type: AddressArr}, - }.Pack(big.NewInt(1), newAxelarProxy, targets) + }.Pack(UpgradeMsgID, common.HexToAddress(newAxelarProxy), targetAddrs) }