forked from ComposableFi/picasso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
514 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" | ||
"github.com/strangelove-ventures/interchaintest/v8/ibc" | ||
"github.com/strangelove-ventures/interchaintest/v8/testutil" | ||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
) | ||
|
||
func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contractAddr, queryMsg string, res interface{}) error { | ||
var jsonMap map[string]interface{} | ||
if err := json.Unmarshal([]byte(queryMsg), &jsonMap); err != nil { | ||
t.Fatal(err) | ||
} | ||
err := chain.QueryContract(ctx, contractAddr, jsonMap, &res) | ||
return err | ||
} | ||
|
||
func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string) (codeId string) { | ||
codeId, err := chain.StoreContract(ctx, keyname, fileLoc) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return codeId | ||
} | ||
|
||
func SetupContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string, message string, extraFlags ...string) (codeId, contract string) { | ||
codeId = StoreContract(t, ctx, chain, keyname, fileLoc) | ||
|
||
needsNoAdminFlag := true | ||
// if extraFlags contains "--admin", switch to false | ||
for _, flag := range extraFlags { | ||
if flag == "--admin" { | ||
needsNoAdminFlag = false | ||
} | ||
} | ||
|
||
contractAddr, err := chain.InstantiateContract(ctx, keyname, codeId, message, needsNoAdminFlag, extraFlags...) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
return codeId, contractAddr | ||
} | ||
|
||
func MigrateContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, contractAddr string, fileLoc string, message string) (codeId, contract string) { | ||
codeId, err := chain.StoreContract(ctx, keyname, fileLoc) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Execute migrate tx | ||
cmd := []string{ | ||
"junod", "tx", "wasm", "migrate", contractAddr, codeId, message, | ||
"--node", chain.GetRPCAddress(), | ||
"--home", chain.HomeDir(), | ||
"--chain-id", chain.Config().ChainID, | ||
"--from", keyname, | ||
"--gas", "500000", | ||
"--keyring-dir", chain.HomeDir(), | ||
"--keyring-backend", keyring.BackendTest, | ||
"-y", | ||
} | ||
|
||
stdout, _, err := chain.Exec(ctx, cmd, nil) | ||
require.NoError(t, err) | ||
|
||
debugOutput(t, string(stdout)) | ||
|
||
if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
return codeId, contractAddr | ||
} | ||
|
||
func ExecuteMsgWithAmount(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, message string) { | ||
// amount is #utoken | ||
|
||
// There has to be a way to do this in ictest? | ||
cmd := []string{ | ||
"junod", "tx", "wasm", "execute", contractAddr, message, | ||
"--node", chain.GetRPCAddress(), | ||
"--home", chain.HomeDir(), | ||
"--chain-id", chain.Config().ChainID, | ||
"--from", user.KeyName(), | ||
"--gas", "500000", | ||
"--amount", amount, | ||
"--keyring-dir", chain.HomeDir(), | ||
"--keyring-backend", keyring.BackendTest, | ||
"-y", | ||
} | ||
stdout, _, err := chain.Exec(ctx, cmd, nil) | ||
require.NoError(t, err) | ||
|
||
debugOutput(t, string(stdout)) | ||
|
||
if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func ExecuteMsgWithFee(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, feeCoin, message string) { | ||
// amount is #utoken | ||
|
||
// There has to be a way to do this in ictest? | ||
cmd := []string{ | ||
"junod", "tx", "wasm", "execute", contractAddr, message, | ||
"--node", chain.GetRPCAddress(), | ||
"--home", chain.HomeDir(), | ||
"--chain-id", chain.Config().ChainID, | ||
"--from", user.KeyName(), | ||
"--gas", "500000", | ||
"--fees", feeCoin, | ||
"--keyring-dir", chain.HomeDir(), | ||
"--keyring-backend", keyring.BackendTest, | ||
"-y", | ||
} | ||
|
||
if amount != "" { | ||
cmd = append(cmd, "--amount", amount) | ||
} | ||
|
||
stdout, _, err := chain.Exec(ctx, cmd, nil) | ||
require.NoError(t, err) | ||
|
||
debugOutput(t, string(stdout)) | ||
|
||
if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func ExecuteMsgWithFeeReturn(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, feeCoin, message string) (*sdk.TxResponse, error) { | ||
// amount is #utoken | ||
|
||
// There has to be a way to do this in ictest? (there is, use node.ExecTx) | ||
cmd := []string{ | ||
"wasm", "execute", contractAddr, message, | ||
"--output", "json", | ||
"--node", chain.GetRPCAddress(), | ||
"--home", chain.HomeDir(), | ||
"--gas", "500000", | ||
"--fees", feeCoin, | ||
"--keyring-dir", chain.HomeDir(), | ||
} | ||
|
||
if amount != "" { | ||
cmd = append(cmd, "--amount", amount) | ||
} | ||
|
||
node := chain.GetNode() | ||
|
||
txHash, err := node.ExecTx(ctx, user.KeyName(), cmd...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// convert stdout into a TxResponse | ||
txRes, err := chain.GetTransaction(txHash) | ||
return txRes, err | ||
} | ||
|
||
func debugOutput(t *testing.T, stdout string) { | ||
if true { | ||
t.Log(stdout) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func GetIBCHooksUserAddress(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, channel, uaddr string) string { | ||
// picad q ibchooks wasm-sender channel-0 "contractAddr" --node http://localhost:26657 | ||
cmd := []string{ | ||
"picad", "query", "ibchooks", "wasm-sender", channel, uaddr, | ||
"--node", chain.GetRPCAddress(), | ||
"--chain-id", chain.Config().ChainID, | ||
"--output", "json", | ||
} | ||
|
||
// This query does not return a type, just prints the string. | ||
stdout, _, err := chain.Exec(ctx, cmd, nil) | ||
require.NoError(t, err) | ||
|
||
address := strings.Replace(string(stdout), "\n", "", -1) | ||
return address | ||
} | ||
|
||
func GetIBCHookTotalFunds(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contract string, uaddr string) GetTotalFundsResponse { | ||
var res GetTotalFundsResponse | ||
err := chain.QueryContract(ctx, contract, QueryMsg{GetTotalFunds: &GetTotalFundsQuery{Addr: uaddr}}, &res) | ||
require.NoError(t, err) | ||
return res | ||
} | ||
|
||
func GetIBCHookCount(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contract string, uaddr string) GetCountResponse { | ||
var res GetCountResponse | ||
err := chain.QueryContract(ctx, contract, QueryMsg{GetCount: &GetCountQuery{Addr: uaddr}}, &res) | ||
require.NoError(t, err) | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package helpers | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// Go based data types for querying on the contract. | ||
// Execute types are not needed here. We just use strings. Could add though in the future and to_string it | ||
|
||
// EntryPoint | ||
type QueryMsg struct { | ||
// Tokenfactory Core | ||
GetConfig *struct{} `json:"get_config,omitempty"` | ||
GetBalance *GetBalanceQuery `json:"get_balance,omitempty"` | ||
GetAllBalances *GetAllBalancesQuery `json:"get_all_balances,omitempty"` | ||
|
||
// Unity Contract | ||
GetWithdrawalReadyTime *struct{} `json:"get_withdrawal_ready_time,omitempty"` | ||
|
||
// IBCHooks | ||
GetCount *GetCountQuery `json:"get_count,omitempty"` | ||
GetTotalFunds *GetTotalFundsQuery `json:"get_total_funds,omitempty"` | ||
} | ||
|
||
type GetAllBalancesQuery struct { | ||
Address string `json:"address"` | ||
} | ||
type GetAllBalancesResponse struct { | ||
// or is it wasm Coin type? | ||
Data []sdk.Coin `json:"data"` | ||
} | ||
|
||
type GetBalanceQuery struct { | ||
// {"get_balance":{"address":"juno1...","denom":"factory/juno1.../RcqfWz"}} | ||
Address string `json:"address"` | ||
Denom string `json:"denom"` | ||
} | ||
type GetBalanceResponse struct { | ||
// or is it wasm Coin type? | ||
Data sdk.Coin `json:"data"` | ||
} | ||
|
||
type WithdrawalTimestampResponse struct { | ||
// {"data":{"withdrawal_ready_timestamp":"1686146048614053435"}} | ||
Data *WithdrawalTimestampObj `json:"data"` | ||
} | ||
type WithdrawalTimestampObj struct { | ||
WithdrawalReadyTimestamp string `json:"withdrawal_ready_timestamp"` | ||
} | ||
|
||
type GetTotalFundsQuery struct { | ||
// {"get_total_funds":{"addr":"juno1..."}} | ||
Addr string `json:"addr"` | ||
} | ||
type GetTotalFundsResponse struct { | ||
// {"data":{"total_funds":[{"denom":"ibc/04F5F501207C3626A2C14BFEF654D51C2E0B8F7CA578AB8ED272A66FE4E48097","amount":"1"}]}} | ||
Data *GetTotalFundsObj `json:"data"` | ||
} | ||
type GetTotalFundsObj struct { | ||
TotalFunds []WasmCoin `json:"total_funds"` | ||
} | ||
|
||
type WasmCoin struct { | ||
Denom string `json:"denom"` | ||
Amount string `json:"amount"` | ||
} | ||
|
||
type GetCountQuery struct { | ||
// {"get_total_funds":{"addr":"juno1..."}} | ||
Addr string `json:"addr"` | ||
} | ||
type GetCountResponse struct { | ||
// {"data":{"count":0}} | ||
Data *GetCountObj `json:"data"` | ||
} | ||
type GetCountObj struct { | ||
Count int64 `json:"count"` | ||
} | ||
|
||
type ClockContractResponse struct { | ||
Data *ClockContractObj `json:"data"` | ||
} | ||
type ClockContractObj struct { | ||
Val uint32 `json:"val"` | ||
} | ||
|
||
type GetCwHooksDelegationResponse struct { | ||
// {"data":{"validator_address":"%s","delegator_address":"%s","shares":"%s"}} | ||
Data *GetDelegationObj `json:"data"` | ||
} | ||
type GetDelegationObj struct { | ||
ValidatorAddress string `json:"validator_address"` | ||
DelegatorAddress string `json:"delegator_address"` | ||
Shares string `json:"shares"` | ||
} |
Oops, something went wrong.