Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor(nexus): general message deprecated methods removal #2011

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x/axelarnet/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewProposalHandler(k keeper.Keeper, nexusK types.Nexus, accountK types.Acco
payloadHash := crypto.Keccak256(contractCall.Payload)

msgID, txID, nonce := nexusK.GenerateMessageID(ctx)
msg := nexus.NewGeneralMessage_(msgID, sender, recipient, payloadHash, txID, nonce, nil)
msg := nexus.NewGeneralMessage(msgID, sender, recipient, payloadHash, txID, nonce, nil)

events.Emit(ctx, &types.ContractCallSubmitted{
MessageID: msg.ID,
Expand All @@ -123,7 +123,7 @@ func NewProposalHandler(k keeper.Keeper, nexusK types.Nexus, accountK types.Acco
Payload: contractCall.Payload,
})

if err := nexusK.SetNewMessage_(ctx, msg); err != nil {
if err := nexusK.SetNewMessage(ctx, msg); err != nil {
return sdkerrors.Wrap(err, "failed to add general message")
}

Expand Down
6 changes: 3 additions & 3 deletions x/axelarnet/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s msgServer) CallContract(c context.Context, req *types.CallContractReques
payloadHash := crypto.Keccak256(req.Payload)

msgID, txID, nonce := s.nexus.GenerateMessageID(ctx)
msg := nexus.NewGeneralMessage_(msgID, sender, recipient, payloadHash, txID, nonce, nil)
msg := nexus.NewGeneralMessage(msgID, sender, recipient, payloadHash, txID, nonce, nil)

events.Emit(ctx, &types.ContractCallSubmitted{
MessageID: msg.ID,
Expand Down Expand Up @@ -111,7 +111,7 @@ func (s msgServer) CallContract(c context.Context, req *types.CallContractReques
events.Emit(ctx, &feePaidEvent)
}

if err := s.nexus.SetNewMessage_(ctx, msg); err != nil {
if err := s.nexus.SetNewMessage(ctx, msg); err != nil {
return nil, sdkerrors.Wrap(err, "failed to add general message")
}

Expand Down Expand Up @@ -518,7 +518,7 @@ func (s msgServer) RouteMessage(c context.Context, req *types.RouteMessageReques
}
}

err := s.nexus.SetMessageProcessing_(ctx, msg.ID)
err := s.nexus.SetMessageProcessing(ctx, msg.ID)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions x/axelarnet/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ func TestRouteMessage(t *testing.T) {
GetChainByNativeAssetFunc: func(sdk.Context, string) (nexus.Chain, bool) {
return chain, true
},
SetMessageProcessing_Func: func(sdk.Context, string) error {
SetMessageProcessingFunc: func(sdk.Context, string) error {
return nil
},
}
Expand Down Expand Up @@ -1267,7 +1267,7 @@ func TestHandleCallContract(t *testing.T) {
})

whenSetNewMessageSucceeds := When("set new message succeeds", func() {
nexusK.SetNewMessage_Func = func(_ sdk.Context, m nexus.GeneralMessage) error {
nexusK.SetNewMessageFunc = func(_ sdk.Context, m nexus.GeneralMessage) error {
msg = m
return m.ValidateBasic()
}
Expand Down Expand Up @@ -1378,7 +1378,7 @@ func TestHandleCallContract(t *testing.T) {
When2(whenChainIsActivated).
When2(whenAddressIsValid).
When("set new message fails", func() {
nexusK.SetNewMessage_Func = func(_ sdk.Context, m nexus.GeneralMessage) error {
nexusK.SetNewMessageFunc = func(_ sdk.Context, m nexus.GeneralMessage) error {
return fmt.Errorf("failed to set message")
}
}).
Expand Down
8 changes: 4 additions & 4 deletions x/axelarnet/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func handleMessage(ctx sdk.Context, n types.Nexus, b types.BankKeeper, sourceAdd

destChain := funcs.MustOk(n.GetChain(ctx, nexus.ChainName(msg.DestinationChain)))
recipient := nexus.CrossChainAddress{Chain: destChain, Address: msg.DestinationAddress}
m := nexus.NewGeneralMessage_(
m := nexus.NewGeneralMessage(
id,
sourceAddress,
recipient,
Expand All @@ -266,7 +266,7 @@ func handleMessage(ctx sdk.Context, n types.Nexus, b types.BankKeeper, sourceAdd
Payload: msg.Payload,
})

return n.SetNewMessage_(ctx, m)
return n.SetNewMessage(ctx, m)
}

func handleMessageWithToken(ctx sdk.Context, n types.Nexus, b types.BankKeeper, sourceAddress nexus.CrossChainAddress, msg Message, token keeper.Coin) error {
Expand All @@ -283,7 +283,7 @@ func handleMessageWithToken(ctx sdk.Context, n types.Nexus, b types.BankKeeper,

destChain := funcs.MustOk(n.GetChain(ctx, nexus.ChainName(msg.DestinationChain)))
recipient := nexus.CrossChainAddress{Chain: destChain, Address: msg.DestinationAddress}
m := nexus.NewGeneralMessage_(
m := nexus.NewGeneralMessage(
id,
sourceAddress,
recipient,
Expand All @@ -304,7 +304,7 @@ func handleMessageWithToken(ctx sdk.Context, n types.Nexus, b types.BankKeeper,
Asset: token.Coin,
})

return n.SetNewMessage_(ctx, m)
return n.SetNewMessage(ctx, m)
}

func handleTokenSent(ctx sdk.Context, n types.Nexus, b types.BankKeeper, sourceAddress nexus.CrossChainAddress, msg Message, token keeper.Coin) error {
Expand Down
6 changes: 3 additions & 3 deletions x/axelarnet/message_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestHandleMessage(t *testing.T) {
}))
channelK.SendPacketFunc = func(sdk.Context, *captypes.Capability, ibcexported.PacketI) error { return nil }
n = &mock.NexusMock{
SetNewMessage_Func: func(ctx sdk.Context, msg nexus.GeneralMessage) error {
SetNewMessageFunc: func(ctx sdk.Context, msg nexus.GeneralMessage) error {
genMsg = msg
return nil
},
Expand Down Expand Up @@ -473,7 +473,7 @@ func TestHandleMessageWithToken(t *testing.T) {

channelK.SendPacketFunc = func(sdk.Context, *captypes.Capability, ibcexported.PacketI) error { return nil }
n = &mock.NexusMock{
SetNewMessage_Func: func(ctx sdk.Context, msg nexus.GeneralMessage) error {
SetNewMessageFunc: func(ctx sdk.Context, msg nexus.GeneralMessage) error {
genMsg = msg
return nil
},
Expand Down Expand Up @@ -689,7 +689,7 @@ func TestHandleSendToken(t *testing.T) {

channelK.SendPacketFunc = func(sdk.Context, *captypes.Capability, ibcexported.PacketI) error { return nil }
n = &mock.NexusMock{
SetNewMessage_Func: func(sdk.Context, nexus.GeneralMessage) error { return nil },
SetNewMessageFunc: func(sdk.Context, nexus.GeneralMessage) error { return nil },
GetChainFunc: func(ctx sdk.Context, chain nexus.ChainName) (nexus.Chain, bool) {
switch chain {
case srcChain.Name:
Expand Down
2 changes: 0 additions & 2 deletions x/axelarnet/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ type Nexus interface {
RateLimitTransfer(ctx sdk.Context, chain nexus.ChainName, asset sdk.Coin, direction nexus.TransferDirection) error
GetMessage(ctx sdk.Context, id string) (m nexus.GeneralMessage, found bool)
SetNewMessage(ctx sdk.Context, m nexus.GeneralMessage) error
SetNewMessage_(ctx sdk.Context, m nexus.GeneralMessage) error
SetMessageProcessing(ctx sdk.Context, id string) error
SetMessageProcessing_(ctx sdk.Context, id string) error
SetMessageExecuted(ctx sdk.Context, id string) error
SetMessageFailed(ctx sdk.Context, id string) error
GenerateMessageID(ctx sdk.Context) (string, []byte, uint64)
Expand Down
100 changes: 0 additions & 100 deletions x/axelarnet/types/mock/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions x/evm/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ func setMessageToNexus(ctx sdk.Context, n types.Nexus, event types.Event, asset
sender,
recipient,
e.ContractCall.PayloadHash.Bytes(),
nexus.Approved,
event.TxID.Bytes(),
event.Index,
nil,
Expand All @@ -245,7 +244,6 @@ func setMessageToNexus(ctx sdk.Context, n types.Nexus, event types.Event, asset
sender,
recipient,
e.ContractCallWithToken.PayloadHash.Bytes(),
nexus.Approved,
event.TxID.Bytes(),
event.Index,
asset,
Expand Down
7 changes: 5 additions & 2 deletions x/evm/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestHandleGeneralMessage(t *testing.T) {
asset := rand.Coin()

givenMessage := Given("a message", func() {
msg = nexus.NewGeneralMessage(evmTestUtils.RandomHash().Hex(), sender, receiver, evmCrypto.Keccak256(payload), nexus.Approved, evmTestUtils.RandomHash().Bytes()[:], uint64(rand.I64Between(0, 10000)), nil)
msg = nexus.NewGeneralMessage(evmTestUtils.RandomHash().Hex(), sender, receiver, evmCrypto.Keccak256(payload), evmTestUtils.RandomHash().Bytes()[:], uint64(rand.I64Between(0, 10000)), nil)

ctx, _, n, multisigKeeper, _, destinationCk = setup()
n.SetMessageFailedFunc = func(ctx sdk.Context, id string) error {
Expand Down Expand Up @@ -280,7 +280,10 @@ func TestHandleGeneralMessages(t *testing.T) {
destChain.Module = types.ModuleName
sender := nexus.CrossChainAddress{Chain: srcChain, Address: evmTestUtils.RandomAddress().Hex()}
receiver := nexus.CrossChainAddress{Chain: destChain, Address: evmTestUtils.RandomAddress().Hex()}
msg := nexus.NewGeneralMessage(evmTestUtils.RandomHash().Hex(), sender, receiver, evmTestUtils.RandomHash().Bytes(), nexus.Processing, evmTestUtils.RandomHash().Bytes()[:], uint64(rand.I64Between(0, 10000)), nil)

msg := nexus.NewGeneralMessage(evmTestUtils.RandomHash().Hex(), sender, receiver, evmTestUtils.RandomHash().Bytes(), evmTestUtils.RandomHash().Bytes()[:], uint64(rand.I64Between(0, 10000)), nil)
msg.Status = nexus.Processing

msgs = append(msgs, msg)
}
return msgs
Expand Down
2 changes: 1 addition & 1 deletion x/evm/types/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestNewApproveContractCallCommandFromGeneralMessage(t *testing.T) {
destChain := nexus.Chain{Name: nexus.ChainName(rand.StrBetween(8, 64)), Module: types.ModuleName}
sender := nexus.CrossChainAddress{Chain: srcChain, Address: rand.AccAddr().String()}
receiver := nexus.CrossChainAddress{Chain: destChain, Address: testutils.RandomAddress().Hex()}
msg := nexus.NewGeneralMessage(txID.Hex(), sender, receiver, payloadHash, nexus.Approved, txID[:], eventIndex, nil)
msg := nexus.NewGeneralMessage(txID.Hex(), sender, receiver, payloadHash, txID[:], eventIndex, nil)

actual := types.NewApproveContractCallCommandGeneric(chainID, keyID,
common.HexToAddress(msg.GetDestinationAddress()), common.BytesToHash(msg.PayloadHash), common.BytesToHash(msg.SourceTxID), msg.GetSourceChain(), msg.GetSourceAddress(), msg.SourceTxIndex, msg.ID)
Expand Down
7 changes: 5 additions & 2 deletions x/nexus/exported/testutils/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ func RandomMessage(statuses ...exported.GeneralMessage_Status) exported.GeneralM
statuses = []exported.GeneralMessage_Status{exported.Approved, exported.Processing, exported.Executed, exported.Failed}
}
coin := rand.Coin()
return exported.NewGeneralMessage(

msg := exported.NewGeneralMessage(
rand.StrBetween(10, 20),
RandomCrossChainAddress(),
RandomCrossChainAddress(),
rand.Bytes(32),
rand.Of(statuses...),
rand.Bytes(32),
uint64(rand.I64Between(0, 10000)),
&coin,
)
msg.Status = rand.Of(statuses...)

return msg
}
19 changes: 2 additions & 17 deletions x/nexus/exported/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,8 @@ func (m TransferDirection) ValidateBasic() error {
}
}

// NewGeneralMessage returns a GeneralMessage struct
// Deprecated: use NewGeneralMessage_ instead
func NewGeneralMessage(id string, sender CrossChainAddress, recipient CrossChainAddress, payloadHash []byte, status GeneralMessage_Status, sourceTxID []byte, sourceTxIndex uint64, asset *sdk.Coin) GeneralMessage {
return GeneralMessage{
ID: id,
Sender: sender,
Recipient: recipient,
PayloadHash: payloadHash,
Status: status,
Asset: asset,
SourceTxID: sourceTxID,
SourceTxIndex: sourceTxIndex,
}
}

// NewGeneralMessage_ returns a GeneralMessage struct with status set to approved
func NewGeneralMessage_(id string, sender CrossChainAddress, recipient CrossChainAddress, payloadHash []byte, sourceTxID []byte, sourceTxIndex uint64, asset *sdk.Coin) GeneralMessage {
// NewGeneralMessage returns a GeneralMessage struct with status set to approved
func NewGeneralMessage(id string, sender CrossChainAddress, recipient CrossChainAddress, payloadHash []byte, sourceTxID []byte, sourceTxIndex uint64, asset *sdk.Coin) GeneralMessage {
return GeneralMessage{
ID: id,
Sender: sender,
Expand Down
Loading
Loading