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

test: add liquidity testing to integration testing #549

Merged
merged 1 commit into from
Jun 5, 2024
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
12 changes: 11 additions & 1 deletion tests/crosschain_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
45 changes: 45 additions & 0 deletions tests/crosschain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
1 change: 1 addition & 0 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestIntegrationTest(t *testing.T) {

func (suite *IntegrationTest) TestRun() {
suite.CrossChainTest()
suite.LiquidityTest()
suite.OriginalCrossChainTest()

suite.PrecompileTransferCrossChainTest()
Expand Down
1 change: 1 addition & 0 deletions tests/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading