Skip to content

Commit

Permalink
test: add host zone proposal interchain test
Browse files Browse the repository at this point in the history
  • Loading branch information
Duong Minh Ngoc committed Jan 17, 2024
1 parent 4e33a53 commit f931227
Show file tree
Hide file tree
Showing 7 changed files with 652 additions and 1 deletion.
61 changes: 61 additions & 0 deletions tests/interchaintest/feeabs/proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package feeabs

import (
"context"
"fmt"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"os"
"path/filepath"
)

func DeleteHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) {
tn := c.Validators[0]
if len(c.FullNodes) > 0 {
tn = c.FullNodes[0]
}
dat, err := os.ReadFile(fileLocation)
if err != nil {
return "", fmt.Errorf("failed to read file: %w", err)
}

fileName := "delete-hostzone.json"

err = tn.WriteFile(ctx, dat, fileName)
if err != nil {
return "", fmt.Errorf("writing delete host zone proposal: %w", err)
}

filePath := filepath.Join(tn.HomeDir(), fileName)

command := []string{
"gov", "submit-legacy-proposal",
"delete-hostzone-config", filePath,
}
return tn.ExecTx(ctx, keyName, command...)
}

func SetHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) {
tn := c.Validators[0]
if len(c.FullNodes) > 0 {
tn = c.FullNodes[0]
}
dat, err := os.ReadFile(fileLocation)
if err != nil {
return "", fmt.Errorf("failed to read file: %w", err)
}

fileName := "set-hostzone.json"

err = tn.WriteFile(ctx, dat, fileName)
if err != nil {
return "", fmt.Errorf("writing set host zone proposal: %w", err)
}

filePath := filepath.Join(tn.HomeDir(), fileName)

command := []string{
"gov", "submit-legacy-proposal",
"set-hostzone-config", filePath,
}
return tn.ExecTx(ctx, keyName, command...)
}
34 changes: 34 additions & 0 deletions tests/interchaintest/feeabs/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package feeabs

import (
"context"
"encoding/json"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
)

type HostChainFeeAbsConfigResponse struct {
HostChainConfig HostChainFeeAbsConfig `json:"host_chain_config"`
}

type HostChainFeeAbsConfig struct {
IbcDenom string `json:"ibc_denom"`
OsmosisPoolTokenDenomIn string `json:"osmosis_pool_token_denom_in"`
PoolId string `json:"pool_id"`
Frozen bool `json:"frozen"`
}

func QueryFeeabsHostZoneConfigWithDenom(c *cosmos.CosmosChain, ctx context.Context, denom string) (*HostChainFeeAbsConfigResponse, error) {
cmd := []string{"feeabs", "host-chain-config", denom}
stdout, _, err := c.ExecQuery(ctx, cmd)
if err != nil {
return &HostChainFeeAbsConfigResponse{}, err
}

var hostZoneConfig HostChainFeeAbsConfigResponse
err = json.Unmarshal(stdout, &hostZoneConfig)
if err != nil {
return &HostChainFeeAbsConfigResponse{}, err
}

return &hostZoneConfig, nil
}
Loading

0 comments on commit f931227

Please sign in to comment.