Skip to content

Commit

Permalink
Dang/add test mint (#134)
Browse files Browse the repository at this point in the history
* change stake to upica

* add query escrow address

* add proposal

* add test mint

* nit

* minor

* lint

---------

Co-authored-by: vuong <nguyenvuong1122000@gmail.com>
  • Loading branch information
GNaD13 and vuong177 committed May 26, 2023
1 parent 806f431 commit c51f7f1
Show file tree
Hide file tree
Showing 11 changed files with 695 additions and 34 deletions.
13 changes: 13 additions & 0 deletions proto/banksy/transfermiddleware/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ service Query {
rpc ParaTokenInfo(QueryParaTokenInfoRequest) returns (QueryParaTokenInfoResponse) {
option (google.api.http).get = "/banksy/paratokeninfo";
}
rpc EscrowAddress(QueryEscrowAddressRequest) returns (QueryEscrowAddressResponse) {
option (google.api.http).get = "/banksy/escrowaddress";
}
}

// message QueryEscrowAddressRequest
message QueryEscrowAddressRequest {
string channel_id = 1 [(gogoproto.moretags) = "yaml:\"channel_id\""];
}

// QueryEscrowAddressResponse
message QueryEscrowAddressResponse {
string escrow_address = 1 [(gogoproto.moretags) = "yaml:\"escrow_address\""];
}

// QueryParaTokenInfoRequest is the request type for the Query/Params RPC method.
Expand Down
18 changes: 18 additions & 0 deletions scripts/mint_test/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# Run this script to quickly install, setup, and run the current version of juno without docker.
# Test address cosmos1hce8cea32gjg9eaqzxj02jrgc6m6q59wly4zpm

CHANNEL_ID="channel-0"

ESCROW_ADDRESS=$(banksyd q transfermiddleware escrow-address channel-0)

hermes --config scripts/relayer_hermes/config_compose_gaia.toml create channel --a-chain banksyd-t1 --b-chain gaiad-t1 --a-port transfer --b-port transfer --new-client-connection --yes

gaiad tx ibc-transfer transfer transfer channel-0 "$ESCROW_ADDRESS" 1000000000stake --from gnad --keyring-backend test --chain-id gaiad-t1 --yes --fees 5000stake
sleep 20
balancesEscrowAdress = $(banksyd query bank balances $ESCROW_ADDRESS)

banksyd

banksyd tx ibc-transfer transfer transfer channel-0 cosmos1hce8cea32gjg9eaqzxj02jrgc6m6q59wly4zpm

8 changes: 4 additions & 4 deletions scripts/node_start/runnode_banksyd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ from_scratch () {
update_test_genesis '.app_state["feeshare"]["params"]["allowed_denoms"]=["stake"]'

# Allocate genesis accounts
banksyd add-genesis-account $KEY 10000000000000stake,100000000000000utest --keyring-backend $KEYRING
banksyd add-genesis-account myaccount 10000000000000stake,100000000000000utest --keyring-backend $KEYRING
banksyd add-genesis-account $KEY 1000000000stake,100000000000000utest --keyring-backend $KEYRING
banksyd add-genesis-account myaccount 1000000000stake,100000000000000utest --keyring-backend $KEYRING

banksyd gentx $KEY 10000000000000stake --keyring-backend $KEYRING --chain-id $CHAINID
banksyd gentx $KEY 1000000000stake --keyring-backend $KEYRING --chain-id $CHAINID

# Collect genesis tx
banksyd collect-gentxs
Expand All @@ -79,7 +79,7 @@ sed -i 's/enable = false/enable = true/g' ~/.banksy/config/app.toml
sed -i '/address = "tcp:\/\/0.0.0.0:1317"/c\address = "tcp:\/\/0.0.0.0:1318"' ~/.banksy/config/app.toml

banksyd config node tcp://0.0.0.0:2241
banksyd start --pruning=nothing --minimum-gas-prices=0.0001stake --p2p.laddr tcp://0.0.0.0:2240 --rpc.laddr tcp://0.0.0.0:2241 --grpc.address 0.0.0.0:2242 --grpc-web.address 0.0.0.0:2243
banksyd start --pruning=nothing --minimum-gas-prices=0stake --p2p.laddr tcp://0.0.0.0:2240 --rpc.laddr tcp://0.0.0.0:2241 --grpc.address 0.0.0.0:2242 --grpc-web.address 0.0.0.0:2243

#MEMO='{"forward":{"receiver":"cosmos18p5cs3z0q68hq7q0d8tr8kp3ldnqkx2fx3f88w","port":"transfer","channel":"channel-0","timeout":600000000000,"retries":0,"next":"{}"}'
#hermes --config scripts/relayer_hermes/config_compose_gaia.toml create channel --a-chain banksyd-t1 --b-chain gaiad-t1 --a-port transfer --b-port transfer --new-client-connection --yes
Expand Down
6 changes: 3 additions & 3 deletions scripts/node_start/runnode_gaia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ from_scratch () {
update_test_genesis '.app_state["feeshare"]["params"]["allowed_denoms"]=["stake"]'

# Allocate genesis accounts
gaiad add-genesis-account $KEY 10000000000000uatom,10000000000000stake,100000000000000utest --keyring-backend $KEYRING
gaiad add-genesis-account gnad 10000000000000uatom,10000000000000stake,100000000000000utest --keyring-backend $KEYRING
gaiad add-genesis-account $KEY 10000000000000uatom,10000000000stake,100000000000000utest --keyring-backend $KEYRING
gaiad add-genesis-account gnad 10000000000000uatom,10000000000stake,100000000000000utest --keyring-backend $KEYRING

gaiad gentx $KEY 10000000000000stake --keyring-backend $KEYRING --chain-id $CHAINID
gaiad gentx $KEY 10000000000stake --keyring-backend $KEYRING --chain-id $CHAINID

# Collect genesis tx
gaiad collect-gentxs
Expand Down
14 changes: 14 additions & 0 deletions scripts/proposalAddToken.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"messages": [
{
"@type": "/banksy.transfermiddleware.v1beta1.MsgAddParachainIBCTokenInfo",
"ibc_denom": "cosmos1...", // The gov module module address
"channel_id": "cosmos1...",
"native_denom": ""
}
],
"metadata": "AQ==",
"deposit": "10stake",
"title": "Proposal Title",
"summary": "Proposal Summary"
}
27 changes: 27 additions & 0 deletions x/transfermiddleware/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func GetQueryCmd() *cobra.Command {

queryCmd.AddCommand(
GetCmdParaTokenInfo(),
GetEscowAddress(),
)

return queryCmd
Expand Down Expand Up @@ -54,6 +55,32 @@ func GetCmdParaTokenInfo() *cobra.Command {
return cmd
}

func GetEscowAddress() *cobra.Command {
cmd := &cobra.Command{
Use: "escrow-address [channel-id]",
Short: "Query the escrow address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.EscrowAddress(cmd.Context(), &types.QueryEscrowAddressRequest{
ChannelId: args[0],
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// NewTxCmd returns the transaction commands for router
func NewTxCmd() *cobra.Command {
return nil
Expand Down
9 changes: 9 additions & 0 deletions x/transfermiddleware/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/notional-labs/banksy/v2/x/transfermiddleware/types"
)

Expand All @@ -17,3 +18,11 @@ func (k Keeper) ParaTokenInfo(c context.Context, req *types.QueryParaTokenInfoRe
ChannelId: info.ChannelId,
}, nil
}

func (k Keeper) EscrowAddress(c context.Context, req *types.QueryEscrowAddressRequest) (*types.QueryEscrowAddressResponse, error) {

Check warning on line 22 in x/transfermiddleware/keeper/grpc_query.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'c' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 22 in x/transfermiddleware/keeper/grpc_query.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'c' seems to be unused, consider removing or renaming it as _ (revive)
escrowAddress := transfertypes.GetEscrowAddress(transfertypes.PortID, req.ChannelId)

return &types.QueryEscrowAddressResponse{
EscrowAddress: escrowAddress.String(),
}, nil
}
1 change: 1 addition & 0 deletions x/transfermiddleware/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
voucher := sdk.NewCoin(voucherDenom, transferAmount)

paraTokenInfo := k.GetParachainIBCTokenInfo(ctx, data.Denom)

if k.GetNativeDenomByIBCDenomSecondaryIndex(ctx, denomTrace.IBCDenom()) != paraTokenInfo.NativeDenom {
return nil
}
Expand Down
113 changes: 113 additions & 0 deletions x/transfermiddleware/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package transfermiddleware_test

import (
"fmt"
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
customibctesting "github.com/notional-labs/banksy/v2/app/ibctesting"
"github.com/stretchr/testify/suite"
)

func (suite *TransferMiddlewareTestSuite) TestSendTransfer() {
Expand Down Expand Up @@ -362,3 +364,114 @@ func (suite *TransferMiddlewareTestSuite) TestTimeOutPacket() {
chainBSenderBalances := suite.chainB.AllBalances(suite.chainB.SenderAccount.GetAddress())
suite.Equal(expBalance, chainBSenderBalances)
}

func TestTransferMiddlewareTestSuiteTestSuite(t *testing.T) {
suite.Run(t, new(TransferMiddlewareTestSuite))
}

func (suite *TransferMiddlewareTestSuite) TestMintAndBurnProcessWhenLaunchChain() {
var (
transferAmount, _ = sdk.NewIntFromString("10000000000000000000")
// when transfer via sdk transfer from A (module) -> B (contract)
timeoutHeight = clienttypes.NewHeight(1, 110)
path *customibctesting.Path
expDenom = "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878"
transferAmountFromChainBToChainA = sdk.NewInt(1000000000)

// pathBtoC = NewTransferPath(suite.chainB, suite.chainC)
)

testCases := []struct {
name string
}{
{
"Test Mint",
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest()
// When setup chainB(Composable already have 10^19 stake in test account (genesis))
path = NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

senderABalance := suite.chainB.Balance(suite.chainB.SenderAccount.GetAddress(), "stake")

// Send coin from picasso (chainA) to escrow address
escrowAddress := ibctransfertypes.GetEscrowAddress(ibctransfertypes.PortID, path.EndpointB.ChannelID)
msg := ibctransfertypes.NewMsgTransfer(
path.EndpointA.ChannelConfig.PortID,
path.EndpointA.ChannelID,
senderABalance,
suite.chainA.SenderAccount.GetAddress().String(),
escrowAddress.String(),
timeoutHeight,
0,
"",
)
_, err := suite.chainA.SendMsgs(msg)
suite.Require().NoError(err)
suite.Require().NoError(err, path.EndpointB.UpdateClient())

// then
suite.Require().Equal(1, len(suite.chainA.PendingSendPackets))
suite.Require().Equal(0, len(suite.chainB.PendingSendPackets))

// and when relay to chain B and handle Ack on chain A
err = suite.coordinator.RelayAndAckPendingPackets(path)
suite.Require().NoError(err)

// then
suite.Require().Equal(0, len(suite.chainA.PendingSendPackets))
suite.Require().Equal(0, len(suite.chainB.PendingSendPackets))

balance := suite.chainB.AllBalances(escrowAddress)
expBalance := sdk.NewCoins(sdk.NewCoin(expDenom, transferAmount))
suite.Require().Equal(expBalance, balance)

// Add parachain token info
chainBtransMiddleware := suite.chainB.TransferMiddleware()
err = chainBtransMiddleware.AddParachainIBCInfo(suite.chainB.GetContext(), expDenom, path.EndpointB.ChannelID, sdk.DefaultBondDenom)
suite.Require().NoError(err)

// send coin from B to A
msg = ibctransfertypes.NewMsgTransfer(
path.EndpointB.ChannelConfig.PortID,
path.EndpointB.ChannelID,
sdk.NewCoin("stake", transferAmountFromChainBToChainA),
suite.chainB.SenderAccount.GetAddress().String(),
suite.chainA.SenderAccount.GetAddress().String(),
timeoutHeight,
0,
"",
)
_, err = suite.chainB.SendMsgs(msg)
suite.Require().NoError(err)
suite.Require().NoError(err, path.EndpointA.UpdateClient())

// then
suite.Require().Equal(1, len(suite.chainB.PendingSendPackets))
suite.Require().Equal(0, len(suite.chainA.PendingSendPackets))

// and when relay to chain A and handle Ack on chain B
err = suite.coordinator.RelayAndAckPendingPacketsReverse(path)
suite.Require().NoError(err)

// then
suite.Require().Equal(0, len(suite.chainB.PendingSendPackets))
suite.Require().Equal(0, len(suite.chainA.PendingSendPackets))

balance = suite.chainB.AllBalances(suite.chainB.SenderAccount.GetAddress())
expBalance = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, transferAmount.Sub(transferAmountFromChainBToChainA)))
suite.Require().Equal(expBalance, balance)

balance = suite.chainB.AllBalances(escrowAddress)
expBalance = sdk.NewCoins(sdk.NewCoin(expDenom, transferAmount.Sub(transferAmountFromChainBToChainA)))
suite.Require().Equal(expBalance, balance)

balance = suite.chainA.AllBalances(suite.chainA.SenderAccount.GetAddress())
expBalance = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, transferAmountFromChainBToChainA))
suite.Require().Equal(expBalance, balance)
})
}
}
Loading

0 comments on commit c51f7f1

Please sign in to comment.