Skip to content
Closed
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
3 changes: 2 additions & 1 deletion tests/interchaintest/chain_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"github.com/oraichain/wasmd/tests/interchaintest/helpers"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestStartOrai(t *testing.T) {
_ = ic.Close()
})

a, err := orai.AuthQueryModuleAccounts(ctx)
a, err := helpers.QueryAuthModuleAccounts(t, ctx, orai)

require.NoError(t, err)
t.Log("module accounts", a)
Expand Down
28 changes: 28 additions & 0 deletions tests/interchaintest/helpers/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package helpers

import (
"context"
"encoding/json"
"testing"

"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
)

// Query helpers
// QueryParam returns the state and details of a subspace param.
func QueryAuthModuleAccounts(t *testing.T,
ctx context.Context,
chain *cosmos.CosmosChain,
) (AuthModuleAccounts, error) {
tn := chain.GetNode()
stdout, _, err := tn.ExecQuery(ctx, "auth", "module-accounts", "--output", "json")
if err != nil {
return AuthModuleAccounts{}, err
}
var accs AuthModuleAccounts
err = json.Unmarshal(stdout, &accs)
if err != nil {
return AuthModuleAccounts{}, err
}
return accs, nil
}
83 changes: 83 additions & 0 deletions tests/interchaintest/helpers/bank.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package helpers

import (
"context"
"encoding/json"
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
)

func QueryBankBalance(
t *testing.T,
ctx context.Context,
chain *cosmos.CosmosChain,
denom string,
userAddress string,
) (uint64, error) {
tn := chain.GetNode()
stdout, _, err := tn.ExecQuery(ctx, "bank", "balance", userAddress, denom)
if err != nil {
return 0, err
}
if stdout == nil {
return 0, err
}

var balance QueryBalanceResponse
err = json.Unmarshal(stdout, &balance)
if err != nil {
return 0, err
}

return balance.Balance.Amount.Uint64(), nil
}

func QueryBankBalances(
t *testing.T,
ctx context.Context,
chain *cosmos.CosmosChain,
userAddress string,
) (sdk.Coins, error) {
tn := chain.GetNode()
stdout, _, err := tn.ExecQuery(ctx, "bank", "balances", userAddress)
if err != nil {
fmt.Println("Error query bank balances ")
return sdk.Coins{}, err
}

fmt.Println("Bank balances: ", string(stdout))
if stdout == nil {
return sdk.Coins{}, err
}

var balance QueryAllBalancesResponse
err = json.Unmarshal(stdout, &balance)
if err != nil {
return sdk.Coins{}, err
}

return balance.Balances, nil
}

// Query helpers
// QueryParam returns the state and details of a subspace param.
func QueryBankDenomMetadata(t *testing.T,
ctx context.Context,
chain *cosmos.CosmosChain,
denom string,
) (QueryDenomMetadataResponse, error) {
tn := chain.GetNode()
stdout, _, err := tn.ExecQuery(ctx, "bank", "denom-metadata", denom, "--output", "json")
if err != nil {
return QueryDenomMetadataResponse{}, err
}
var metadata QueryDenomMetadataResponse
err = json.Unmarshal(stdout, &metadata)
if err != nil {
return QueryDenomMetadataResponse{}, err
}
return metadata, nil
}
31 changes: 31 additions & 0 deletions tests/interchaintest/helpers/gov.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package helpers

import (
"context"
"encoding/json"
"testing"

// govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
// "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
)

// Query helpers
// QueryParam returns the state and details of a subspace param.
func QueryGovProposalStatus(t *testing.T,
ctx context.Context,
chain *cosmos.CosmosChain,
propId string,
) (QueryProposalResponse, error) {
tn := chain.GetNode()
stdout, _, err := tn.ExecQuery(ctx, "gov", "proposal", propId, "--output", "json")
if err != nil {
return QueryProposalResponse{}, err
}
var proposal QueryProposalResponse
err = json.Unmarshal(stdout, &proposal)
if err != nil {
return QueryProposalResponse{}, err
}
return proposal, nil
}
99 changes: 99 additions & 0 deletions tests/interchaintest/helpers/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package helpers

import (
"time"

types1 "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

type ParamChange struct {
Expand All @@ -20,6 +24,24 @@ type TokenFactoryParams struct {
DenomCreationGasConsume string `json:"denom_creation_gas_consume,omitempty"`
}

type Account struct {
AccountNumber uint64 `json:"account_number"`
Address string `json:"address"`
Name string `json:"name"`
Permissions []string `json:"permissions"`
PublicKey string `json:"public_key"`
Sequence uint64 `json:"sequence"`
}

type ModuleAccount struct {
Type string `json:"type"`
Value Account `json:"value"`
}

type AuthModuleAccounts struct {
Accounts []ModuleAccount `json:"accounts"`
}

type QueryDenomsFromCreatorResponse struct {
Denoms []string `json:"denoms"`
}
Expand Down Expand Up @@ -56,3 +78,80 @@ type HackatomExampleInitMsg struct {
type QuerySqrtPriceResponse struct {
Data string `json:"data,omitempty"`
}

type QueryProposalResponse struct {
Proposal Proposal `protobuf:"bytes,1,opt,name=proposal,proto3" json:"proposal"`
}

type Proposal struct {
// id defines the unique id of the proposal.
Id string `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
// messages are the arbitrary messages to be executed if the proposal passes.
Messages []*types1.Any `protobuf:"bytes,2,rep,name=messages,proto3" json:"messages,omitempty"`
// status defines the proposal status.
Status string `protobuf:"varint,3,opt,name=status,proto3,enum=cosmos.gov.v1.ProposalStatus" json:"status,omitempty"`
// final_tally_result is the final tally result of the proposal. When
// querying a proposal via gRPC, this field is not populated until the
// proposal's voting period has ended.
FinalTallyResult *TallyResult `protobuf:"bytes,4,opt,name=final_tally_result,json=finalTallyResult,proto3" json:"final_tally_result,omitempty"`
// submit_time is the time of proposal submission.
SubmitTime *time.Time `protobuf:"bytes,5,opt,name=submit_time,json=submitTime,proto3,stdtime" json:"submit_time,omitempty"`
// deposit_end_time is the end time for deposition.
DepositEndTime *time.Time `protobuf:"bytes,6,opt,name=deposit_end_time,json=depositEndTime,proto3,stdtime" json:"deposit_end_time,omitempty"`
// total_deposit is the total deposit on the proposal.
TotalDeposit []sdk.Coin `protobuf:"bytes,7,rep,name=total_deposit,json=totalDeposit,proto3" json:"total_deposit"`
// voting_start_time is the starting time to vote on a proposal.
VotingStartTime *time.Time `protobuf:"bytes,8,opt,name=voting_start_time,json=votingStartTime,proto3,stdtime" json:"voting_start_time,omitempty"`
// voting_end_time is the end time of voting on a proposal.
VotingEndTime *time.Time `protobuf:"bytes,9,opt,name=voting_end_time,json=votingEndTime,proto3,stdtime" json:"voting_end_time,omitempty"`
// metadata is any arbitrary metadata attached to the proposal.
// the recommended format of the metadata is to be found here:
// https://docs.cosmos.network/v0.47/modules/gov#proposal-3
Metadata string `protobuf:"bytes,10,opt,name=metadata,proto3" json:"metadata,omitempty"`
// title is the title of the proposal
//
// Since: cosmos-sdk 0.47
Title string `protobuf:"bytes,11,opt,name=title,proto3" json:"title,omitempty"`
// summary is a short summary of the proposal
//
// Since: cosmos-sdk 0.47
Summary string `protobuf:"bytes,12,opt,name=summary,proto3" json:"summary,omitempty"`
// proposer is the address of the proposal sumbitter
//
// Since: cosmos-sdk 0.47
Proposer string `protobuf:"bytes,13,opt,name=proposer,proto3" json:"proposer,omitempty"`
// expedited defines if the proposal is expedited
//
// Since: cosmos-sdk 0.50
Expedited bool `protobuf:"varint,14,opt,name=expedited,proto3" json:"expedited,omitempty"`
// failed_reason defines the reason why the proposal failed
//
// Since: cosmos-sdk 0.50
FailedReason string `protobuf:"bytes,15,opt,name=failed_reason,json=failedReason,proto3" json:"failed_reason,omitempty"`
}

type TallyResult struct {
// yes_count is the number of yes votes on a proposal.
YesCount string `protobuf:"bytes,1,opt,name=yes_count,json=yesCount,proto3" json:"yes_count,omitempty"`
// abstain_count is the number of abstain votes on a proposal.
AbstainCount string `protobuf:"bytes,2,opt,name=abstain_count,json=abstainCount,proto3" json:"abstain_count,omitempty"`
// no_count is the number of no votes on a proposal.
NoCount string `protobuf:"bytes,3,opt,name=no_count,json=noCount,proto3" json:"no_count,omitempty"`
// no_with_veto_count is the number of no with veto votes on a proposal.
NoWithVetoCount string `protobuf:"bytes,4,opt,name=no_with_veto_count,json=noWithVetoCount,proto3" json:"no_with_veto_count,omitempty"`
}

type QueryDenomMetadataResponse struct {
// metadata describes and provides all the client information for the requested token.
Metadata banktypes.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata"`
}

type QueryBalanceResponse struct {
// balance is the balance of the coin.
Balance *sdk.Coin `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance,omitempty"`
}

type QueryAllBalancesResponse struct {
// balances is the balances of all the coins.
Balances sdk.Coins `protobuf:"bytes,1,rep,name=balances,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"balances"`
}
11 changes: 6 additions & 5 deletions tests/interchaintest/ibc_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"github.com/oraichain/wasmd/tests/interchaintest/helpers"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
Expand Down Expand Up @@ -71,9 +72,9 @@ func TestIbcHooks(t *testing.T) {
gaiaIBCDenom := transfertypes.ParseDenomTrace(gaiaDenom).IBCDenom() // ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2

// check contract address balance
balances, err := orai.BankQueryBalance(ctx, contractAddress, gaiaIBCDenom)
balances, err := helpers.QueryBankBalance(t, ctx, orai, gaiaIBCDenom, contractAddress)
require.NoError(t, err)
require.Equal(t, math.NewInt(0), balances)
require.Equal(t, uint64(0), balances)

// send ibc transaction to execite the contract
transfer := ibc.WalletAmount{
Expand All @@ -92,11 +93,11 @@ func TestIbcHooks(t *testing.T) {
require.NoError(t, err)

// check new balances
balances, err = orai.BankQueryBalance(ctx, contractAddress, gaiaIBCDenom)
balances, err = helpers.QueryBankBalance(t, ctx, orai, gaiaIBCDenom, contractAddress)
require.NoError(t, err)
require.Equal(t, amountToSend, balances)
require.Equal(t, amountToSend, math.NewInt(int64(balances)))

// check contract
// check contractx
var res GetCountResponse
err = orai.QueryContract(ctx, contractAddress, QueryMsg{GetCount: &GetCountQuery{}}, &res)
require.NoError(t, err)
Expand Down
14 changes: 8 additions & 6 deletions tests/interchaintest/orai_osmo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func TestTokenFactoryForceTransferWithIbc(t *testing.T) {
require.NoError(t, err)

users := CreateTestingUser(t, ctx, t.Name(), genesisWalletAmount, chains...)
// Wait a few blocks for relayer to start and for user accounts to be created
err = testutil.WaitForBlocks(ctx, 5, orai, osmo)
require.NoError(t, err)
// Get our Bech32 encoded user addresses
oraiUser, osmoUser := users[0], users[1]

Expand All @@ -69,7 +72,7 @@ func TestTokenFactoryForceTransferWithIbc(t *testing.T) {
// mint token
tokenToMint := uint64(100_000_000_000)
_ = helpers.TxTokenFactoryMintToken(t, ctx, orai, oraiUser, expectedDenom, tokenToMint)
oraiUserBalance, err := helpers.QueryBalance(t, ctx, orai, expectedDenom, oraiUserAddress)
oraiUserBalance, err := helpers.QueryBankBalance(t, ctx, orai, expectedDenom, oraiUserAddress)
require.NoError(t, err)
require.Equal(t, tokenToMint, oraiUserBalance)

Expand All @@ -78,7 +81,7 @@ func TestTokenFactoryForceTransferWithIbc(t *testing.T) {
escrowedAddress := sdk.MustBech32ifyAddressBytes(orai.Config().Bech32Prefix, addr.Bytes())

// balance before transfer ibc must be 0
escrowedBalance, err := helpers.QueryBalance(t, ctx, orai, expectedDenom, escrowedAddress)
escrowedBalance, err := helpers.QueryBankBalance(t, ctx, orai, expectedDenom, escrowedAddress)
require.NoError(t, err)
require.Equal(t, escrowedBalance, uint64(0))

Expand All @@ -89,7 +92,7 @@ func TestTokenFactoryForceTransferWithIbc(t *testing.T) {
oraiIBCDenom := transfertypes.ParseDenomTrace(oraiDenom).IBCDenom()

// osmosis user balance before transfer ibc must be 0
userOsmosisBalance, err := helpers.QueryBalance(t, ctx, osmo, oraiIBCDenom, osmoUserAddr)
userOsmosisBalance, err := helpers.QueryBankBalance(t, ctx, osmo, oraiIBCDenom, osmoUserAddr)
require.NoError(t, err)
require.Equal(t, userOsmosisBalance, uint64(0))

Expand All @@ -109,8 +112,7 @@ func TestTokenFactoryForceTransferWithIbc(t *testing.T) {
require.NoError(t, err)

// balance after transfer ibc must be equalt amount to send
escrowedBalance, err = helpers.QueryBalance(t, ctx, orai, expectedDenom, escrowedAddress)
fmt.Println("escrowed balance: ", escrowedBalance)
escrowedBalance, err = helpers.QueryBankBalance(t, ctx, orai, expectedDenom, escrowedAddress)
require.NoError(t, err)
require.Equal(t, escrowedBalance, uint64(amountToSend.Int64()))

Expand All @@ -123,7 +125,7 @@ func TestTokenFactoryForceTransferWithIbc(t *testing.T) {
_, err = helpers.TxTokenFactoryForceTransfer(t, ctx, orai, oraiUser, expectedDenom, uint64(amountToSend.Int64()), escrowedAddress, oraiUserAddress)
require.Error(t, err)

escrowedBalance, err = helpers.QueryBalance(t, ctx, orai, expectedDenom, escrowedAddress)
escrowedBalance, err = helpers.QueryBankBalance(t, ctx, orai, expectedDenom, escrowedAddress)
fmt.Println("escrowed balance: ", escrowedBalance)
require.NoError(t, err)
require.Equal(t, escrowedBalance, uint64(amountToSend.Int64()))
Expand Down
Loading
Loading