diff --git a/tests/crosschain_suite.go b/tests/crosschain_suite.go index fc72c8c1..4738ae78 100644 --- a/tests/crosschain_suite.go +++ b/tests/crosschain_suite.go @@ -98,6 +98,15 @@ func (suite *CrosschainTestSuite) QueryPendingUnbatchedTx(sender sdk.AccAddress) return pendingTx.UnbatchedTransfers } +func (suite *CrosschainTestSuite) QueryPendingPoolSendToExternal(sender sdk.AccAddress) []*crosschaintypes.PendingOutgoingTransferTx { + response, err := suite.CrosschainQuery().GetPendingPoolSendToExternal(suite.ctx, &crosschaintypes.QueryPendingPoolSendToExternalRequest{ + ChainName: suite.chainName, + SenderAddress: sender.String(), + }) + suite.NoError(err) + return response.GetTxs() +} + func (suite *CrosschainTestSuite) queryFxLastEventNonce() uint64 { lastEventNonce, err := suite.CrosschainQuery().LastEventNonceByAddr(suite.ctx, &crosschaintypes.QueryLastEventNonceByAddrRequest{ @@ -344,7 +353,8 @@ func (suite *CrosschainTestSuite) SendToExternalAndResponse(count int, amount sd continue } for _, attribute := range event.Attributes { - if attribute.Key != crosschaintypes.AttributeKeyOutgoingTxID { + if attribute.Key != crosschaintypes.AttributeKeyOutgoingTxID && + attribute.Key != crosschaintypes.AttributeKeyPendingOutgoingTxID { continue } txId, err := strconv.ParseUint(attribute.Value, 10, 64) diff --git a/tests/crosschain_test.go b/tests/crosschain_test.go index d7e4a9af..a9b7c9af 100644 --- a/tests/crosschain_test.go +++ b/tests/crosschain_test.go @@ -246,3 +246,48 @@ func (suite *IntegrationTest) BridgeCallToFxcoreTest() { } } } + +func (suite *IntegrationTest) LiquidityTest() { + chainModules := []string{ethtypes.ModuleName, bsctypes.ModuleName} + tokenAliases := make([]string, 0, len(chainModules)) + moduleTokenMap := make(map[string]string) + moduleDenomMap := make(map[string]string) + metadata := fxtypes.GetCrossChainMetadataManyToOne("test token", helpers.NewRandSymbol(), 18) + for _, chainName := range chainModules { + suiteChain := suite.GetCrossChainByName(chainName) + tokenAddress := helpers.GenExternalAddr(suiteChain.chainName) + moduleTokenMap[chainName] = tokenAddress + bridgeDenom := crosschaintypes.NewBridgeDenom(suiteChain.chainName, tokenAddress) + moduleDenomMap[chainName] = bridgeDenom + tokenAliases = append(tokenAliases, bridgeDenom) + suiteChain.AddBridgeTokenClaim(metadata.Name, metadata.Symbol, uint64(metadata.DenomUnits[1].Exponent), tokenAddress, "") + } + metadata.DenomUnits[0].Aliases = tokenAliases + suite.erc20.RegisterCoinProposal(metadata) + + ethChain := suite.GetCrossChainByName(ethtypes.ModuleName) + bscChain := suite.GetCrossChainByName(bsctypes.ModuleName) + + transferAmount := sdk.NewInt(100) + ethChain.SendToFxClaimAndCheckBalance(moduleTokenMap[ethtypes.ModuleName], transferAmount, "", sdk.NewCoin(metadata.Base, transferAmount)) + ethChain.CheckBalance(ethChain.AccAddress(), sdk.NewCoin(metadata.Base, transferAmount)) + ethChain.CheckBalance(ethChain.AccAddress(), sdk.NewCoin(moduleDenomMap[ethtypes.ModuleName], sdkmath.NewInt(0))) + + ethChain.Send(bscChain.AccAddress(), sdk.NewCoin(metadata.Base, transferAmount)) + bscChain.SendToExternalAndCheckBalance(sdk.NewCoin(metadata.Base, transferAmount)) + suite.Equal(0, len(bscChain.QueryPendingUnbatchedTx(bscChain.AccAddress()))) + + pendingPoolSendToExternal := bscChain.QueryPendingPoolSendToExternal(bscChain.AccAddress()) + suite.Equal(1, len(pendingPoolSendToExternal)) + outgoingTransferTx := pendingPoolSendToExternal[0] + suite.EqualValues(sdk.NewCoin(moduleDenomMap[bscChain.chainName], transferAmount), outgoingTransferTx.Token.Add(outgoingTransferTx.Fee)) + suite.EqualValues(0, len(outgoingTransferTx.Rewards)) + + bscChain.SendToFxClaimAndCheckBalance(moduleTokenMap[bsctypes.ModuleName], transferAmount, "", sdk.NewCoin(metadata.Base, transferAmount)) + suite.Equal(0, len(bscChain.QueryPendingPoolSendToExternal(bscChain.AccAddress()))) + + unbatchedTx := bscChain.QueryPendingUnbatchedTx(bscChain.AccAddress()) + suite.Equal(1, len(unbatchedTx)) + suite.EqualValues(transferAmount, unbatchedTx[0].Token.Amount.Add(unbatchedTx[0].Fee.Amount)) + suite.EqualValues(moduleTokenMap[bscChain.chainName], unbatchedTx[0].Token.GetContract()) +} diff --git a/tests/integration_test.go b/tests/integration_test.go index dff00834..b745069c 100644 --- a/tests/integration_test.go +++ b/tests/integration_test.go @@ -65,6 +65,7 @@ func TestIntegrationTest(t *testing.T) { func (suite *IntegrationTest) TestRun() { suite.CrossChainTest() + suite.LiquidityTest() suite.OriginalCrossChainTest() suite.PrecompileTransferCrossChainTest() diff --git a/tests/suite.go b/tests/suite.go index 8b8af2e2..a3672510 100644 --- a/tests/suite.go +++ b/tests/suite.go @@ -115,6 +115,7 @@ func (suite *TestSuite) SetupSuite() { baseDir, err := os.MkdirTemp(suite.T().TempDir(), cfg.ChainID) suite.Require().NoError(err) suite.network, err = network.New(suite.T(), baseDir, cfg) + suite.Require().NoError(err) time.Sleep(timeoutCommit * 10) for suite.BlockNumber() <= 3 {