-
Notifications
You must be signed in to change notification settings - Fork 178
fix(crosschain): reject paused zrc20 v2 inbounds #4588
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -254,6 +254,35 @@ func TestKeeper_GetErc20InboundDetails(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.Empty(t, result) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Run("fail when foreign coin is paused", func(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ARRANGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| UseFungibleMock: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zrc20 := sample.EthAddress() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| callEvent := false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreignCoin := fungibletypes.ForeignCoins{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Zrc20ContractAddress: zrc20.Hex(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Asset: "USDT", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ForeignChainId: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CoinType: coin.CoinType_ERC20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Paused: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fungibleMock.On("GetForeignCoins", ctx, zrc20.Hex()).Return(foreignCoin, true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ACT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result, err := k.GetERC20InboundDetails(ctx, zrc20, callEvent) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ASSERT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.Error(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.ErrorIs(t, err, fungibletypes.ErrPausedZRC20) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.Contains(t, err.Error(), "zrc20 "+zrc20.Hex()+" is paused") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.Empty(t, result) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Run("fail when chain is not supported", func(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ARRANGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -322,6 +351,35 @@ func TestKeeper_GetErc20InboundDetails(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.Contains(t, err.Error(), "gas limit query failed") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Run("fail when foreign coin is paused for call event", func(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ARRANGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| UseFungibleMock: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zrc20 := sample.EthAddress() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| callEvent := true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreignCoin := fungibletypes.ForeignCoins{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Zrc20ContractAddress: zrc20.Hex(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Asset: "USDT", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ForeignChainId: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CoinType: coin.CoinType_ERC20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Paused: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+354
to
+370
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: x/crosschain/keeper/v2_zevm_inbound_test.go
Line: 354-370
Comment:
Same `Zrc20ContractAddress` mismatch in the call-event paused test. Using `zrc20.Hex()` matches the real data shape where `GetForeignCoins(zrc20.Hex())` returns a coin whose own `Zrc20ContractAddress` equals the lookup key.
```suggestion
t.Run("fail when foreign coin is paused for call event", func(t *testing.T) {
// ARRANGE
k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
UseFungibleMock: true,
})
zrc20 := sample.EthAddress()
callEvent := true
fungibleMock := keepertest.GetCrosschainFungibleMock(t, k)
foreignCoin := fungibletypes.ForeignCoins{
Zrc20ContractAddress: zrc20.Hex(),
Asset: "USDT",
ForeignChainId: 1,
CoinType: coin.CoinType_ERC20,
Paused: true,
}
```
How can I resolve this? If you propose a fix, please make it concise.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed on the current branch as well: the call-event paused test now uses |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fungibleMock.On("GetForeignCoins", ctx, zrc20.Hex()).Return(foreignCoin, true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ACT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result, err := k.GetERC20InboundDetails(ctx, zrc20, callEvent) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ASSERT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.Error(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.ErrorIs(t, err, fungibletypes.ErrPausedZRC20) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.Contains(t, err.Error(), "zrc20 "+zrc20.Hex()+" is paused") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.Empty(t, result) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Run("success with call event (NoAssetCall)", func(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ARRANGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foreignCoin.Zrc20ContractAddressis a freshly-sampled random address that differs from thezrc20variable passed as input. In production,GetForeignCoins(ctx, zrc20.Hex())returns the coin whoseZrc20ContractAddressequalszrc20.Hex(). Usingzrc20.Hex()for this field aligns the test fixture with the real data shape, making it immediately clear to a reader that the coin belongs to the same address under test.Prompt To Fix With AI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed on the current branch: the paused-coin test now sets
Zrc20ContractAddress: zrc20.Hex(), matching the lookup key used byGetForeignCoins(ctx, zrc20.Hex()).