From 4cd752eacb8bce7f1dfabdbbe5cda7fa636726c4 Mon Sep 17 00:00:00 2001 From: Dan Kanefsky Date: Wed, 16 Oct 2024 12:21:21 -0700 Subject: [PATCH] chore: update cctp tests --- e2e/cctp_deposit_for_burn_test.go | 70 +++++++------- e2e/cctp_deposit_for_burn_with_caller_test.go | 68 ++++++------- e2e/cctp_receive_message_test.go | 90 ++++++++++-------- e2e/cctp_receive_message_with_caller_test.go | 95 +++++++++++-------- e2e/cctp_replace_deposit_for_burn_test.go | 52 +++++----- e2e/utils.go | 30 +++--- 6 files changed, 224 insertions(+), 181 deletions(-) diff --git a/e2e/cctp_deposit_for_burn_test.go b/e2e/cctp_deposit_for_burn_test.go index 9bb5947e..8ee55c90 100644 --- a/e2e/cctp_deposit_for_burn_test.go +++ b/e2e/cctp_deposit_for_burn_test.go @@ -34,36 +34,33 @@ func TestCCTP_DepositForBurn(t *testing.T) { user := interchaintest.GetAndFundTestUsers(t, ctx, "wallet", math.OneInt(), noble)[0] _, err := nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MasterMinter.KeyName(), - "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), nw.FiatTfRoles.Minter.FormattedAddress(), "-b", "block", + "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), nw.FiatTfRoles.Minter.FormattedAddress(), ) require.NoError(t, err, "failed to execute configure minter controller tx") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MinterController.KeyName(), - "fiat-tokenfactory", "configure-minter", nw.FiatTfRoles.Minter.FormattedAddress(), "1000000000000"+e2e.DenomMetadataUsdc.Base, "-b", "block", + "fiat-tokenfactory", "configure-minter", nw.FiatTfRoles.Minter.FormattedAddress(), "1000000000000"+e2e.DenomMetadataUsdc.Base, ) require.NoError(t, err, "failed to execute configure minter tx") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), - "fiat-tokenfactory", "mint", user.FormattedAddress(), "1000000000000"+e2e.DenomMetadataUsdc.Base, "-b", "block", + "fiat-tokenfactory", "mint", user.FormattedAddress(), "1000000000000"+e2e.DenomMetadataUsdc.Base, ) require.NoError(t, err, "failed to execute mint to user tx") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MasterMinter.KeyName(), - "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctptypes.ModuleAddress.String(), "-b", "block", + "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctptypes.ModuleAddress.String(), ) require.NoError(t, err, "failed to configure cctp minter controller") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MinterController.KeyName(), - "fiat-tokenfactory", "configure-minter", cctptypes.ModuleAddress.String(), "1000000000000"+e2e.DenomMetadataUsdc.Base, "-b", "block", + "fiat-tokenfactory", "configure-minter", cctptypes.ModuleAddress.String(), "1000000000000"+e2e.DenomMetadataUsdc.Base, ) require.NoError(t, err, "failed to configure cctp minter") // ---- broadcaster := cosmos.NewBroadcaster(t, noble) - // broadcaster.ConfigureClientContextOptions(func(clientContext sdkclient.Context) sdkclient.Context { - // return clientContext.WithBroadcastMode(flags.BroadcastBlock) - // }) burnToken := make([]byte, 32) copy(burnToken[12:], common.FromHex("0x07865c6E87B9F70255377e024ace6630C1Eaa37F")) @@ -71,32 +68,38 @@ func TestCCTP_DepositForBurn(t *testing.T) { tokenMessenger := make([]byte, 32) copy(tokenMessenger[12:], common.FromHex("0xD0C3da58f55358142b8d3e06C1C30c5C6114EFE8")) - msgs := []sdk.Msg{} - - msgs = append(msgs, &cctptypes.MsgAddRemoteTokenMessenger{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - DomainId: 0, - Address: tokenMessenger, - }) - - msgs = append(msgs, &cctptypes.MsgLinkTokenPair{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - RemoteDomain: 0, - RemoteToken: burnToken, - LocalToken: e2e.DenomMetadataUsdc.Base, - }) - bCtx, bCancel := context.WithTimeout(ctx, 20*time.Second) defer bCancel() tx, err := cosmos.BroadcastTx( bCtx, broadcaster, - nw.FiatTfRoles.Owner, - msgs..., + nw.CCTPRoles.Owner, + &cctptypes.MsgAddRemoteTokenMessenger{ + From: nw.CCTPRoles.Owner.FormattedAddress(), + DomainId: 0, + Address: tokenMessenger, + }, + ) + require.NoError(t, err, "error adding remote token messenger") + require.Zero(t, tx.Code, "adding remote token messenger failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) + + bCtx, bCancel = context.WithTimeout(ctx, 20*time.Second) + defer bCancel() + + tx, err = cosmos.BroadcastTx( + bCtx, + broadcaster, + nw.CCTPRoles.TokenController, + &cctptypes.MsgLinkTokenPair{ + From: nw.CCTPRoles.TokenController.FormattedAddress(), + RemoteDomain: 0, + RemoteToken: burnToken, + LocalToken: e2e.DenomMetadataUsdc.Base, + }, ) - require.NoError(t, err, "error configuring remote domain") - require.Zero(t, tx.Code, "configuring remote domain failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) + require.NoError(t, err, "error linking token pair") + require.Zero(t, tx.Code, "linking token pair failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) beforeBurnBal, err := noble.GetBalance(ctx, user.FormattedAddress(), e2e.DenomMetadataUsdc.Base) require.NoError(t, err) @@ -104,7 +107,7 @@ func TestCCTP_DepositForBurn(t *testing.T) { mintRecipient := make([]byte, 32) copy(mintRecipient[12:], common.FromHex("0xfCE4cE85e1F74C01e0ecccd8BbC4606f83D3FC90")) - depositForBurnNoble := &cctptypes.MsgDepositForBurn{ + msgDepositForBurnNoble := &cctptypes.MsgDepositForBurn{ From: user.FormattedAddress(), Amount: math.NewInt(1000000), BurnToken: e2e.DenomMetadataUsdc.Base, @@ -112,11 +115,14 @@ func TestCCTP_DepositForBurn(t *testing.T) { MintRecipient: mintRecipient, } + bCtx, bCancel = context.WithTimeout(ctx, 20*time.Second) + defer bCancel() + tx, err = cosmos.BroadcastTx( bCtx, broadcaster, user, - depositForBurnNoble, + msgDepositForBurnNoble, ) require.NoError(t, err, "error broadcasting msgDepositForBurn") require.Zero(t, tx.Code, "msgDepositForBurn failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) @@ -137,7 +143,7 @@ func TestCCTP_DepositForBurn(t *testing.T) { require.Equal(t, uint64(0), depositForBurn.Nonce) require.Equal(t, expectedBurnToken, depositForBurn.BurnToken) - require.Equal(t, depositForBurnNoble.Amount, depositForBurn.Amount) + require.Equal(t, msgDepositForBurnNoble.Amount, depositForBurn.Amount) require.Equal(t, user.FormattedAddress(), depositForBurn.Depositor) require.Equal(t, mintRecipient, depositForBurn.MintRecipient) require.Equal(t, uint32(0), depositForBurn.DestinationDomain) @@ -156,7 +162,7 @@ func TestCCTP_DepositForBurn(t *testing.T) { messageSender := make([]byte, 32) copy(messageSender[12:], sdk.MustAccAddressFromBech32(cctptypes.ModuleAddress.String())) - expectedBurnToken := crypto.Keccak256([]byte(depositForBurnNoble.BurnToken)) + expectedBurnToken := crypto.Keccak256([]byte(msgDepositForBurnNoble.BurnToken)) moduleAddress := make([]byte, 32) copy(moduleAddress[12:], sdk.MustAccAddressFromBech32(user.FormattedAddress())) @@ -176,7 +182,7 @@ func TestCCTP_DepositForBurn(t *testing.T) { require.Equal(t, uint32(0), body.Version) require.Equal(t, mintRecipient, body.MintRecipient) - require.Equal(t, depositForBurnNoble.Amount, body.Amount) + require.Equal(t, msgDepositForBurnNoble.Amount, body.Amount) require.Equal(t, expectedBurnToken, body.BurnToken) require.Equal(t, moduleAddress, body.MessageSender) } diff --git a/e2e/cctp_deposit_for_burn_with_caller_test.go b/e2e/cctp_deposit_for_burn_with_caller_test.go index a45f6b14..9950bd65 100644 --- a/e2e/cctp_deposit_for_burn_with_caller_test.go +++ b/e2e/cctp_deposit_for_burn_with_caller_test.go @@ -18,7 +18,6 @@ import ( "github.com/stretchr/testify/require" ) -// run `make local-image`to rebuild updated binary before running test func TestCCTP_DepositForBurnWithCaller(t *testing.T) { if testing.Short() { t.Skip() @@ -35,36 +34,33 @@ func TestCCTP_DepositForBurnWithCaller(t *testing.T) { user := interchaintest.GetAndFundTestUsers(t, ctx, "wallet", math.OneInt(), noble)[0] _, err := nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MasterMinter.KeyName(), - "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), nw.FiatTfRoles.Minter.FormattedAddress(), "-b", "block", + "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), nw.FiatTfRoles.Minter.FormattedAddress(), ) require.NoError(t, err, "failed to execute configure minter controller tx") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MinterController.KeyName(), - "fiat-tokenfactory", "configure-minter", nw.FiatTfRoles.Minter.FormattedAddress(), "1000000000000"+e2e.DenomMetadataUsdc.Base, "-b", "block", + "fiat-tokenfactory", "configure-minter", nw.FiatTfRoles.Minter.FormattedAddress(), "1000000000000"+e2e.DenomMetadataUsdc.Base, ) require.NoError(t, err, "failed to execute configure minter tx") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), - "fiat-tokenfactory", "mint", user.FormattedAddress(), "1000000000000"+e2e.DenomMetadataUsdc.Base, "-b", "block", + "fiat-tokenfactory", "mint", user.FormattedAddress(), "1000000000000"+e2e.DenomMetadataUsdc.Base, ) require.NoError(t, err, "failed to execute mint to user tx") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MasterMinter.KeyName(), - "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctptypes.ModuleAddress.String(), "-b", "block", + "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctptypes.ModuleAddress.String(), ) require.NoError(t, err, "failed to configure cctp minter controller") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MinterController.KeyName(), - "fiat-tokenfactory", "configure-minter", cctptypes.ModuleAddress.String(), "1000000000000"+e2e.DenomMetadataUsdc.Base, "-b", "block", + "fiat-tokenfactory", "configure-minter", cctptypes.ModuleAddress.String(), "1000000000000"+e2e.DenomMetadataUsdc.Base, ) require.NoError(t, err, "failed to configure cctp minter") // ---- broadcaster := cosmos.NewBroadcaster(t, noble) - // broadcaster.ConfigureClientContextOptions(func(clientContext sdkclient.Context) sdkclient.Context { - // return clientContext.WithBroadcastMode(flags.BroadcastBlock) - // }) burnToken := make([]byte, 32) copy(burnToken[12:], common.FromHex("0x07865c6E87B9F70255377e024ace6630C1Eaa37F")) @@ -72,32 +68,38 @@ func TestCCTP_DepositForBurnWithCaller(t *testing.T) { tokenMessenger := make([]byte, 32) copy(tokenMessenger[12:], common.FromHex("0xD0C3da58f55358142b8d3e06C1C30c5C6114EFE8")) - msgs := []sdk.Msg{} - - msgs = append(msgs, &cctptypes.MsgAddRemoteTokenMessenger{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - DomainId: 0, - Address: tokenMessenger, - }) - - msgs = append(msgs, &cctptypes.MsgLinkTokenPair{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - RemoteDomain: 0, - RemoteToken: burnToken, - LocalToken: e2e.DenomMetadataUsdc.Base, - }) - bCtx, bCancel := context.WithTimeout(ctx, 20*time.Second) defer bCancel() tx, err := cosmos.BroadcastTx( bCtx, broadcaster, - nw.FiatTfRoles.Owner, - msgs..., + nw.CCTPRoles.Owner, + &cctptypes.MsgAddRemoteTokenMessenger{ + From: nw.FiatTfRoles.Owner.FormattedAddress(), + DomainId: 0, + Address: tokenMessenger, + }, + ) + require.NoError(t, err, "error adding remote token messenger") + require.Zero(t, tx.Code, "adding remote token messenger failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) + + bCtx, bCancel = context.WithTimeout(ctx, 20*time.Second) + defer bCancel() + + tx, err = cosmos.BroadcastTx( + bCtx, + broadcaster, + nw.CCTPRoles.TokenController, + &cctptypes.MsgLinkTokenPair{ + From: nw.CCTPRoles.TokenController.FormattedAddress(), + RemoteDomain: 0, + RemoteToken: burnToken, + LocalToken: e2e.DenomMetadataUsdc.Base, + }, ) - require.NoError(t, err, "error configuring remote domain") - require.Zero(t, tx.Code, "configuring remote domain failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) + require.NoError(t, err, "error linking token pair") + require.Zero(t, tx.Code, "linking token pair failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) beforeBurnBal, err := noble.GetBalance(ctx, user.FormattedAddress(), e2e.DenomMetadataUsdc.Base) require.NoError(t, err) @@ -107,7 +109,7 @@ func TestCCTP_DepositForBurnWithCaller(t *testing.T) { destinationCaller := []byte("12345678901234567890123456789012") - depositForBurnWithCallerNoble := &cctptypes.MsgDepositForBurnWithCaller{ + msgDepositForBurnWithCallerNoble := &cctptypes.MsgDepositForBurnWithCaller{ From: user.FormattedAddress(), Amount: math.NewInt(1000000), BurnToken: e2e.DenomMetadataUsdc.Base, @@ -120,7 +122,7 @@ func TestCCTP_DepositForBurnWithCaller(t *testing.T) { bCtx, broadcaster, user, - depositForBurnWithCallerNoble, + msgDepositForBurnWithCallerNoble, ) require.NoError(t, err, "error broadcasting msgDepositForBurnWithCaller") require.Zero(t, tx.Code, "msgDepositForBurnWithCaller failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) @@ -142,7 +144,7 @@ func TestCCTP_DepositForBurnWithCaller(t *testing.T) { require.Equal(t, uint64(0), depositForBurn.Nonce) require.Equal(t, expectedBurnToken, depositForBurn.BurnToken) - require.Equal(t, depositForBurnWithCallerNoble.Amount, depositForBurn.Amount) + require.Equal(t, msgDepositForBurnWithCallerNoble.Amount, depositForBurn.Amount) require.Equal(t, user.FormattedAddress(), depositForBurn.Depositor) require.Equal(t, mintRecipient, depositForBurn.MintRecipient) require.Equal(t, uint32(0), depositForBurn.DestinationDomain) @@ -161,7 +163,7 @@ func TestCCTP_DepositForBurnWithCaller(t *testing.T) { messageSender := make([]byte, 32) copy(messageSender[12:], sdk.MustAccAddressFromBech32(cctptypes.ModuleAddress.String())) - expectedBurnToken := crypto.Keccak256([]byte(depositForBurnWithCallerNoble.BurnToken)) + expectedBurnToken := crypto.Keccak256([]byte(msgDepositForBurnWithCallerNoble.BurnToken)) moduleAddress := make([]byte, 32) copy(moduleAddress[12:], sdk.MustAccAddressFromBech32(user.FormattedAddress())) @@ -179,7 +181,7 @@ func TestCCTP_DepositForBurnWithCaller(t *testing.T) { require.Equal(t, uint32(0), body.Version) require.Equal(t, mintRecipient, body.MintRecipient) - require.Equal(t, depositForBurnWithCallerNoble.Amount, body.Amount) + require.Equal(t, msgDepositForBurnWithCallerNoble.Amount, body.Amount) require.Equal(t, expectedBurnToken, body.BurnToken) require.Equal(t, moduleAddress, body.MessageSender) } diff --git a/e2e/cctp_receive_message_test.go b/e2e/cctp_receive_message_test.go index 0f5182e8..2742f3fd 100644 --- a/e2e/cctp_receive_message_test.go +++ b/e2e/cctp_receive_message_test.go @@ -10,9 +10,8 @@ import ( "testing" "time" - cosmossdk_io_math "cosmossdk.io/math" + math "cosmossdk.io/math" cctptypes "github.com/circlefin/noble-cctp/x/cctp/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/bech32" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" @@ -22,7 +21,6 @@ import ( "github.com/stretchr/testify/require" ) -// run `make local-image`to rebuild updated binary before running test func TestCCTP_ReceiveMessage(t *testing.T) { if testing.Short() { t.Skip() @@ -34,8 +32,9 @@ func TestCCTP_ReceiveMessage(t *testing.T) { noble := nw.Chain nobleValidator := noble.Validators[0] + broadcaster := cosmos.NewBroadcaster(t, noble) + attesters := make([]*ecdsa.PrivateKey, 2) - msgs := make([]sdk.Msg, 2) // attester - ECDSA public key (Circle will own these keys for mainnet) for i := range attesters { @@ -48,36 +47,25 @@ func TestCCTP_ReceiveMessage(t *testing.T) { attesterPub := hex.EncodeToString(pubKey) + bCtx, bCancel := context.WithTimeout(ctx, 20*time.Second) + defer bCancel() + // Adding an attester to protocal - msgs[i] = &cctptypes.MsgEnableAttester{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - Attester: attesterPub, - } + tx, err := cosmos.BroadcastTx( + bCtx, + broadcaster, + nw.CCTPRoles.AttesterManager, + &cctptypes.MsgEnableAttester{ + From: nw.CCTPRoles.AttesterManager.FormattedAddress(), + Attester: attesterPub, + }, + ) + require.NoError(t, err, "error enabling attester") + require.Zero(t, tx.Code, "cctp enable attester transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) } - broadcaster := cosmos.NewBroadcaster(t, noble) - // broadcaster.ConfigureClientContextOptions(func(clientContext sdkclient.Context) sdkclient.Context { - // return clientContext.WithBroadcastMode(flags.BroadcastBlock) - // }) - - t.Log("preparing to submit add public keys tx") - burnToken := make([]byte, 32) copy(burnToken[12:], common.FromHex("0x07865c6E87B9F70255377e024ace6630C1Eaa37F")) - msgs = append(msgs, &cctptypes.MsgLinkTokenPair{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - RemoteDomain: 0, - RemoteToken: burnToken, - LocalToken: e2e.DenomMetadataUsdc.Base, - }) - - tokenMessenger := make([]byte, 32) - copy(tokenMessenger[12:], common.FromHex("0xBd3fa81B58Ba92a82136038B25aDec7066af3155")) - msgs = append(msgs, &cctptypes.MsgAddRemoteTokenMessenger{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - DomainId: 0, - Address: tokenMessenger, - }) bCtx, bCancel := context.WithTimeout(ctx, 20*time.Second) defer bCancel() @@ -85,13 +73,35 @@ func TestCCTP_ReceiveMessage(t *testing.T) { tx, err := cosmos.BroadcastTx( bCtx, broadcaster, - nw.FiatTfRoles.Owner, - msgs..., + nw.CCTPRoles.TokenController, + &cctptypes.MsgLinkTokenPair{ + From: nw.CCTPRoles.TokenController.FormattedAddress(), + RemoteDomain: 0, + RemoteToken: burnToken, + LocalToken: e2e.DenomMetadataUsdc.Base, + }, ) - require.NoError(t, err, "error submitting add public keys tx") - require.Zero(t, tx.Code, "cctp add pub keys transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) + require.NoError(t, err, "error linking token pair") + require.Zero(t, tx.Code, "cctp link token pair transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) - t.Logf("Submitted add public keys tx: %s", tx.TxHash) + tokenMessenger := make([]byte, 32) + copy(tokenMessenger[12:], common.FromHex("0xBd3fa81B58Ba92a82136038B25aDec7066af3155")) + + bCtx, bCancel = context.WithTimeout(ctx, 20*time.Second) + defer bCancel() + + tx, err = cosmos.BroadcastTx( + bCtx, + broadcaster, + nw.CCTPRoles.Owner, + &cctptypes.MsgAddRemoteTokenMessenger{ + From: nw.CCTPRoles.Owner.FormattedAddress(), + DomainId: 0, + Address: tokenMessenger, + }, + ) + require.NoError(t, err, "error adding remote token messenger") + require.Zero(t, tx.Code, "cctp adding remote token messenger transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) _, bCancel = context.WithTimeout(ctx, 20*time.Second) defer bCancel() @@ -99,12 +109,12 @@ func TestCCTP_ReceiveMessage(t *testing.T) { cctpModuleAccount := authtypes.NewModuleAddress(cctptypes.ModuleName).String() _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MasterMinter.KeyName(), - "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctpModuleAccount, "-b", "block", + "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctpModuleAccount, ) require.NoError(t, err, "failed to execute configure minter controller tx") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MinterController.KeyName(), - "fiat-tokenfactory", "configure-minter", cctpModuleAccount, "1000000"+e2e.DenomMetadataUsdc.Base, "-b", "block", + "fiat-tokenfactory", "configure-minter", cctpModuleAccount, "1000000"+e2e.DenomMetadataUsdc.Base, ) require.NoError(t, err, "failed to execute configure minter tx") @@ -122,7 +132,7 @@ func TestCCTP_ReceiveMessage(t *testing.T) { depositForBurn := cctptypes.BurnMessage{ BurnToken: burnToken, MintRecipient: burnRecipientPadded, - Amount: cosmossdk_io_math.NewInt(1000000), + Amount: math.NewInt(1000000), MessageSender: burnRecipientPadded, } @@ -171,9 +181,9 @@ func TestCCTP_ReceiveMessage(t *testing.T) { tx, err = cosmos.BroadcastTx( bCtx, broadcaster, - nw.FiatTfRoles.Owner, + nw.CCTPRoles.Owner, &cctptypes.MsgReceiveMessage{ //note: all messages that go to noble go through MsgReceiveMessage - From: nw.FiatTfRoles.Owner.FormattedAddress(), + From: nw.CCTPRoles.Owner.FormattedAddress(), Message: wrappedDepositForBurnBz, Attestation: attestationBurn, }, @@ -186,5 +196,5 @@ func TestCCTP_ReceiveMessage(t *testing.T) { balance, err := noble.GetBalance(ctx, nobleReceiver, e2e.DenomMetadataUsdc.Base) require.NoError(t, err) - require.Equal(t, int64(1000000), balance) + require.Equal(t, math.NewInt(1000000), balance) } diff --git a/e2e/cctp_receive_message_with_caller_test.go b/e2e/cctp_receive_message_with_caller_test.go index 868cc1f2..ca36859d 100644 --- a/e2e/cctp_receive_message_with_caller_test.go +++ b/e2e/cctp_receive_message_with_caller_test.go @@ -10,14 +10,14 @@ import ( "testing" "time" - cosmossdk_io_math "cosmossdk.io/math" + math "cosmossdk.io/math" cctptypes "github.com/circlefin/noble-cctp/x/cctp/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/bech32" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/noble-assets/noble/e2e" + "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" "github.com/stretchr/testify/require" ) @@ -33,8 +33,9 @@ func TestCCTP_ReceiveMessageWithCaller(t *testing.T) { noble := nw.Chain nobleValidator := noble.Validators[0] + broadcaster := cosmos.NewBroadcaster(t, noble) + attesters := make([]*ecdsa.PrivateKey, 2) - msgs := make([]sdk.Msg, 2) // attester - ECDSA public key (Circle will own these keys for mainnet) for i := range attesters { @@ -47,36 +48,25 @@ func TestCCTP_ReceiveMessageWithCaller(t *testing.T) { attesterPub := hex.EncodeToString(pubKey) + bCtx, bCancel := context.WithTimeout(ctx, 20*time.Second) + defer bCancel() + // Adding an attester to protocal - msgs[i] = &cctptypes.MsgEnableAttester{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - Attester: attesterPub, - } + tx, err := cosmos.BroadcastTx( + bCtx, + broadcaster, + nw.CCTPRoles.AttesterManager, + &cctptypes.MsgEnableAttester{ + From: nw.CCTPRoles.AttesterManager.FormattedAddress(), + Attester: attesterPub, + }, + ) + require.NoError(t, err, "error enabling attester") + require.Zero(t, tx.Code, "cctp enable attester transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) } - broadcaster := cosmos.NewBroadcaster(t, noble) - // broadcaster.ConfigureClientContextOptions(func(clientContext sdkclient.Context) sdkclient.Context { - // return clientContext.WithBroadcastMode(flags.BroadcastBlock) - // }) - - t.Log("preparing to submit add public keys tx") - burnToken := make([]byte, 32) copy(burnToken[12:], common.FromHex("0x07865c6E87B9F70255377e024ace6630C1Eaa37F")) - msgs = append(msgs, &cctptypes.MsgLinkTokenPair{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - RemoteDomain: 0, - RemoteToken: burnToken, - LocalToken: e2e.DenomMetadataUsdc.Base, - }) - - tokenMessenger := make([]byte, 32) - copy(tokenMessenger[12:], common.FromHex("0xBd3fa81B58Ba92a82136038B25aDec7066af3155")) - msgs = append(msgs, &cctptypes.MsgAddRemoteTokenMessenger{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - DomainId: 0, - Address: tokenMessenger, - }) bCtx, bCancel := context.WithTimeout(ctx, 20*time.Second) defer bCancel() @@ -84,13 +74,35 @@ func TestCCTP_ReceiveMessageWithCaller(t *testing.T) { tx, err := cosmos.BroadcastTx( bCtx, broadcaster, - nw.FiatTfRoles.Owner, - msgs..., + nw.CCTPRoles.TokenController, + &cctptypes.MsgLinkTokenPair{ + From: nw.CCTPRoles.TokenController.FormattedAddress(), + RemoteDomain: 0, + RemoteToken: burnToken, + LocalToken: e2e.DenomMetadataUsdc.Base, + }, ) - require.NoError(t, err, "error submitting add public keys tx") - require.Zero(t, tx.Code, "cctp add pub keys transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) + require.NoError(t, err, "error linking token pair") + require.Zero(t, tx.Code, "cctp link token pair transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) - t.Logf("Submitted add public keys tx: %s", tx.TxHash) + tokenMessenger := make([]byte, 32) + copy(tokenMessenger[12:], common.FromHex("0xBd3fa81B58Ba92a82136038B25aDec7066af3155")) + + bCtx, bCancel = context.WithTimeout(ctx, 20*time.Second) + defer bCancel() + + tx, err = cosmos.BroadcastTx( + bCtx, + broadcaster, + nw.CCTPRoles.Owner, + &cctptypes.MsgAddRemoteTokenMessenger{ + From: nw.CCTPRoles.Owner.FormattedAddress(), + DomainId: 0, + Address: tokenMessenger, + }, + ) + require.NoError(t, err, "error adding remote token messenger") + require.Zero(t, tx.Code, "cctp adding remote token messenger transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) _, bCancel = context.WithTimeout(ctx, 20*time.Second) defer bCancel() @@ -98,12 +110,12 @@ func TestCCTP_ReceiveMessageWithCaller(t *testing.T) { cctpModuleAccount := authtypes.NewModuleAddress(cctptypes.ModuleName).String() _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MasterMinter.KeyName(), - "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctpModuleAccount, "-b", "block", + "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctpModuleAccount, ) require.NoError(t, err, "failed to execute configure minter controller tx") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MinterController.KeyName(), - "fiat-tokenfactory", "configure-minter", cctpModuleAccount, "1000000"+e2e.DenomMetadataUsdc.Base, "-b", "block", + "fiat-tokenfactory", "configure-minter", cctpModuleAccount, "1000000"+e2e.DenomMetadataUsdc.Base, ) require.NoError(t, err, "failed to execute configure minter tx") @@ -121,15 +133,17 @@ func TestCCTP_ReceiveMessageWithCaller(t *testing.T) { depositForBurn := cctptypes.BurnMessage{ BurnToken: burnToken, MintRecipient: burnRecipientPadded, - Amount: cosmossdk_io_math.NewInt(1000000), + Amount: math.NewInt(1000000), MessageSender: burnRecipientPadded, } depositForBurnBz, err := depositForBurn.Bytes() require.NoError(t, err) + relayer := interchaintest.GetAndFundTestUsers(t, ctx, "relayer", math.OneInt(), noble)[0] + destinationCaller := make([]byte, 32) - copy(destinationCaller[12:], nw.FiatTfRoles.Owner.Address()) + copy(destinationCaller[12:], relayer.Address()) wrappedDepositForBurn := cctptypes.Message{ Version: 0, @@ -168,12 +182,13 @@ func TestCCTP_ReceiveMessageWithCaller(t *testing.T) { bCtx, bCancel = context.WithTimeout(ctx, 20*time.Second) defer bCancel() + tx, err = cosmos.BroadcastTx( bCtx, broadcaster, - nw.FiatTfRoles.Owner, + relayer, &cctptypes.MsgReceiveMessage{ //note: all messages that go to noble go through MsgReceiveMessage - From: nw.FiatTfRoles.Owner.FormattedAddress(), + From: relayer.FormattedAddress(), Message: wrappedDepositForBurnBz, Attestation: attestationBurn, }, @@ -186,5 +201,5 @@ func TestCCTP_ReceiveMessageWithCaller(t *testing.T) { balance, err := noble.GetBalance(ctx, nobleReceiver, e2e.DenomMetadataUsdc.Base) require.NoError(t, err) - require.Equal(t, int64(1000000), balance) + require.Equal(t, math.NewInt(1000000), balance) } diff --git a/e2e/cctp_replace_deposit_for_burn_test.go b/e2e/cctp_replace_deposit_for_burn_test.go index 0bacfeb1..ae916db4 100644 --- a/e2e/cctp_replace_deposit_for_burn_test.go +++ b/e2e/cctp_replace_deposit_for_burn_test.go @@ -35,8 +35,9 @@ func TestCCTP_ReplaceDepositForBurn(t *testing.T) { noble := nw.Chain nobleValidator := noble.Validators[0] + broadcaster := cosmos.NewBroadcaster(t, noble) + attesters := make([]*ecdsa.PrivateKey, 2) - msgs := make([]sdk.Msg, 2) // attester - ECDSA public key (Circle will own these keys for mainnet) for i := range attesters { @@ -49,54 +50,55 @@ func TestCCTP_ReplaceDepositForBurn(t *testing.T) { attesterPub := hex.EncodeToString(pubKey) + bCtx, bCancel := context.WithTimeout(ctx, 20*time.Second) + defer bCancel() + // Adding an attester to protocal - msgs[i] = &cctptypes.MsgEnableAttester{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - Attester: attesterPub, - } + tx, err := cosmos.BroadcastTx( + bCtx, + broadcaster, + nw.CCTPRoles.AttesterManager, + &cctptypes.MsgEnableAttester{ + From: nw.CCTPRoles.AttesterManager.FormattedAddress(), + Attester: attesterPub, + }, + ) + require.NoError(t, err, "error enabling attester") + require.Zero(t, tx.Code, "cctp enable attester transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) } - broadcaster := cosmos.NewBroadcaster(t, noble) - // broadcaster.ConfigureClientContextOptions(func(clientContext sdkclient.Context) sdkclient.Context { - // return clientContext.WithBroadcastMode(flags.BroadcastBlock) - // }) - - t.Log("preparing to submit add public keys tx") - burnToken := make([]byte, 32) copy(burnToken[12:], common.FromHex("0x07865c6E87B9F70255377e024ace6630C1Eaa37F")) // maps remote token on remote domain to a local token -- used for minting - msgs = append(msgs, &cctptypes.MsgLinkTokenPair{ - From: nw.FiatTfRoles.Owner.FormattedAddress(), - RemoteDomain: 0, - RemoteToken: burnToken, - LocalToken: e2e.DenomMetadataUsdc.Base, - }) - bCtx, bCancel := context.WithTimeout(ctx, 20*time.Second) defer bCancel() tx, err := cosmos.BroadcastTx( bCtx, broadcaster, - nw.FiatTfRoles.Owner, - msgs..., + nw.CCTPRoles.TokenController, + &cctptypes.MsgLinkTokenPair{ + From: nw.CCTPRoles.TokenController.FormattedAddress(), + RemoteDomain: 0, + RemoteToken: burnToken, + LocalToken: e2e.DenomMetadataUsdc.Base, + }, ) - require.NoError(t, err, "error submitting add public keys tx") - require.Zero(t, tx.Code, "cctp add pub keys transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) + require.NoError(t, err, "error linking token pair") + require.Zero(t, tx.Code, "cctp link token pair transaction failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data) t.Logf("Submitted add public keys tx: %s", tx.TxHash) cctpModuleAccount := authtypes.NewModuleAddress(cctptypes.ModuleName).String() _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MasterMinter.KeyName(), - "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctpModuleAccount, "-b", "block", + "fiat-tokenfactory", "configure-minter-controller", nw.FiatTfRoles.MinterController.FormattedAddress(), cctpModuleAccount, ) require.NoError(t, err, "failed to execute configure minter controller tx") _, err = nobleValidator.ExecTx(ctx, nw.FiatTfRoles.MinterController.KeyName(), - "fiat-tokenfactory", "configure-minter", cctpModuleAccount, "1000000"+e2e.DenomMetadataUsdc.Base, "-b", "block", + "fiat-tokenfactory", "configure-minter", cctpModuleAccount, "1000000"+e2e.DenomMetadataUsdc.Base, ) require.NoError(t, err, "failed to execute configure minter tx") diff --git a/e2e/utils.go b/e2e/utils.go index d012a5d8..c9edb9ec 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -8,7 +8,6 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdktypes "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" @@ -83,6 +82,7 @@ func NobleEncoding() *testutil.TestEncodingConfig { // register custom types fiattokenfactorytypes.RegisterInterfaces(cfg.InterfaceRegistry) + cctptypes.RegisterInterfaces(cfg.InterfaceRegistry) return &cfg } @@ -135,17 +135,19 @@ func modifyGenesisAll(nw *NobleWrapper, setupAllCircleRoles bool) func(cc ibc.Ch if setupAllCircleRoles { allFiatTFRoles := []cosmos.GenesisKV{ cosmos.NewGenesisKV("app_state.fiat-tokenfactory.masterMinter", fiattokenfactorytypes.MasterMinter{Address: nw.FiatTfRoles.MasterMinter.FormattedAddress()}), - cosmos.NewGenesisKV("app_state.fiat-tokenfactory.mintersList", []fiattokenfactorytypes.Minters{{Address: nw.FiatTfRoles.Minter.FormattedAddress(), Allowance: sdktypes.Coin{Denom: DenomMetadataUsdc.Base, Amount: math.NewInt(100_00_000)}}}), + cosmos.NewGenesisKV("app_state.fiat-tokenfactory.mintersList", []fiattokenfactorytypes.Minters{{Address: nw.FiatTfRoles.Minter.FormattedAddress(), Allowance: sdk.Coin{Denom: DenomMetadataUsdc.Base, Amount: math.NewInt(100_00_000)}}}), cosmos.NewGenesisKV("app_state.fiat-tokenfactory.pauser", fiattokenfactorytypes.Pauser{Address: nw.FiatTfRoles.Pauser.FormattedAddress()}), cosmos.NewGenesisKV("app_state.fiat-tokenfactory.blacklister", fiattokenfactorytypes.Blacklister{Address: nw.FiatTfRoles.Blacklister.FormattedAddress()}), cosmos.NewGenesisKV("app_state.fiat-tokenfactory.masterMinter", fiattokenfactorytypes.MasterMinter{Address: nw.FiatTfRoles.MasterMinter.FormattedAddress()}), cosmos.NewGenesisKV("app_state.fiat-tokenfactory.minterControllerList", []fiattokenfactorytypes.MinterController{{Minter: nw.FiatTfRoles.Minter.FormattedAddress(), Controller: nw.FiatTfRoles.MinterController.FormattedAddress()}}), cosmos.NewGenesisKV("app_state.cctp", cctptypes.GenesisState{ - Owner: nw.CCTPRoles.Owner.FormattedAddress(), - AttesterManager: nw.CCTPRoles.AttesterManager.FormattedAddress(), - TokenController: nw.CCTPRoles.TokenController.FormattedAddress(), - NextAvailableNonce: &cctptypes.Nonce{Nonce: 0}, - SignatureThreshold: &cctptypes.SignatureThreshold{Amount: 2}, + Owner: nw.CCTPRoles.Owner.FormattedAddress(), + AttesterManager: nw.CCTPRoles.AttesterManager.FormattedAddress(), + TokenController: nw.CCTPRoles.TokenController.FormattedAddress(), + BurningAndMintingPaused: &cctptypes.BurningAndMintingPaused{Paused: false}, + SendingAndReceivingMessagesPaused: &cctptypes.SendingAndReceivingMessagesPaused{Paused: false}, + NextAvailableNonce: &cctptypes.Nonce{Nonce: 0}, + SignatureThreshold: &cctptypes.SignatureThreshold{Amount: 2}, }), } updatedGenesis = append(updatedGenesis, allFiatTFRoles...) @@ -203,7 +205,7 @@ func createTokenfactoryRoles(ctx context.Context, val *cosmos.ChainNode, setupAl Denom: chainCfg.Denom, Amount: math.ZeroInt(), } - err = val.AddGenesisAccount(ctx, genesisWallet.Address, []sdktypes.Coin{sdktypes.NewCoin(genesisWallet.Denom, genesisWallet.Amount)}) + err = val.AddGenesisAccount(ctx, genesisWallet.Address, []sdk.Coin{sdk.NewCoin(genesisWallet.Denom, genesisWallet.Amount)}) if err != nil { return FiatTfRoles{}, err } @@ -269,7 +271,7 @@ func createTokenfactoryRoles(ctx context.Context, val *cosmos.ChainNode, setupAl } for _, wallet := range genesisWallets { - err = val.AddGenesisAccount(ctx, wallet.Address, []sdktypes.Coin{sdktypes.NewCoin(wallet.Denom, wallet.Amount)}) + err = val.AddGenesisAccount(ctx, wallet.Address, []sdk.Coin{sdk.NewCoin(wallet.Denom, wallet.Amount)}) if err != nil { return FiatTfRoles{}, err } @@ -295,7 +297,7 @@ func createAuthorityRole(ctx context.Context, val *cosmos.ChainNode) (ibc.Wallet Denom: chainCfg.Denom, Amount: math.ZeroInt(), } - err = val.AddGenesisAccount(ctx, genesisWallet.Address, []sdktypes.Coin{sdktypes.NewCoin(genesisWallet.Denom, genesisWallet.Amount)}) + err = val.AddGenesisAccount(ctx, genesisWallet.Address, []sdk.Coin{sdk.NewCoin(genesisWallet.Denom, genesisWallet.Amount)}) if err != nil { return nil, err } @@ -364,6 +366,9 @@ func createCCTPRoles(ctx context.Context, val *cosmos.ChainNode) (CCTPRoles, err // setupAllCircleRoles: if true, all Tokenfactory and CCTP roles will be created and setup at genesis, // if false, only the Owner role will be created func NobleSpinUp(t *testing.T, ctx context.Context, setupAllCircleRoles bool) (nw NobleWrapper) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("noble", "noblepub") + rep := testreporter.NewNopReporter() eRep := rep.RelayerExecReporter(t) @@ -415,6 +420,9 @@ func NobleSpinUpIBC(t *testing.T, ctx context.Context, setupAllCircleRoles bool) client *client.Client, network string, ) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("noble", "noblepub") + rep = testreporter.NewNopReporter() eRep = rep.RelayerExecReporter(t) @@ -577,7 +585,7 @@ func configureMinter(t *testing.T, ctx context.Context, val *cosmos.ChainNode, m expectedShowMinters := fiattokenfactorytypes.QueryGetMintersResponse{ Minters: fiattokenfactorytypes.Minters{ Address: minter.FormattedAddress(), - Allowance: sdktypes.Coin{ + Allowance: sdk.Coin{ Denom: "uusdc", Amount: math.NewInt(allowance), },