Skip to content

Commit

Permalink
Merge branch 'main' into reece/better-wasm-query
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Oct 17, 2023
2 parents ee763ac + 8caf914 commit c35a44f
Show file tree
Hide file tree
Showing 111 changed files with 8,876 additions and 1,655 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,25 @@ jobs:
with:
version: v1.54
only-new-issues: true
args: --timeout=5m
args: --timeout=10m

clippy-lint:
defaults:
run:
working-directory: local-interchain/rust/localic-std
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install stable with clippy and rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
- name: Install clippy
run: rustup component add clippy
- name: Update
run: cargo update
- name: Run clippy
run: make lint

54 changes: 53 additions & 1 deletion .github/workflows/local-interchain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
build:
runs-on: ubuntu-latest
name: build
defaults:
run:
working-directory: ./local-interchain
steps:
- name: Checkout interchaintest
uses: actions/checkout@v4
Expand All @@ -24,4 +27,53 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- run: cd local-interchain && go mod tidy && make install
- name: build local-interchain
run: go mod tidy && make install

- name: Upload localic artifact
uses: actions/upload-artifact@v3
with:
name: local-ic
path: ~/go/bin/local-ic

# TOOO: put the python workflow here. (https://github.com/strangelove-ventures/interchaintest/pull/775)

rust-e2e:
name: rust e2e
needs: build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./local-interchain
strategy:
fail-fast: false

steps:
- name: checkout chain
uses: actions/checkout@v3

- name: Install latest toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: wasm32-unknown-unknown
override: true

- name: Download Tarball Artifact
uses: actions/download-artifact@v3
with:
name: local-ic
path: /tmp

- name: Make local-ic executable
run: chmod +x /tmp/local-ic

- name: Start background ibc local-interchain
run: /tmp/local-ic start juno_ibc --api-port 8080 &

- name: Run Rust Script
run: cd rust && cargo run --package localic-bin --bin localic-bin

- name: Cleanup
run: killall local-ic && exit 0
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: release binary

on:
release:
types: [created]

env:
GO_VERSION: 1.21

jobs:
release-static-binary:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout interchaintest
uses: actions/checkout@v4

- name: Setup go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

# This must be go install vs make install as to not statically link the binary
# to the worker node.
- run: cd local-interchain && go mod tidy && go install ./...

- run: cp $HOME/go/bin/local-ic ./local-ic
- run: chmod +x ./local-ic

- name: Release
uses: softprops/action-gh-release@v1
with:
token: ${{ github.token }}
files: |
local-ic
44 changes: 34 additions & 10 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,16 +444,19 @@ func (tn *ChainNode) FindTxs(ctx context.Context, height uint64) ([]blockdb.Tx,
// with the chain node binary.
func (tn *ChainNode) TxCommand(keyName string, command ...string) []string {
command = append([]string{"tx"}, command...)
var gasPriceFound, gasAdjustmentFound = false, false
var gasPriceFound, gasAdjustmentFound, feesFound = false, false, false
for i := 0; i < len(command); i++ {
if command[i] == "--gas-prices" {
gasPriceFound = true
}
if command[i] == "--gas-adjustment" {
gasAdjustmentFound = true
}
if command[i] == "--fees" {
feesFound = true
}
}
if !gasPriceFound {
if !gasPriceFound && !feesFound {
command = append(command, "--gas-prices", tn.Chain.Config().GasPrices)
}
if !gasAdjustmentFound {
Expand Down Expand Up @@ -779,14 +782,17 @@ type CodeInfosResponse struct {
}

// StoreContract takes a file path to smart contract and stores it on-chain. Returns the contracts code id.
func (tn *ChainNode) StoreContract(ctx context.Context, keyName string, fileName string) (string, error) {
func (tn *ChainNode) StoreContract(ctx context.Context, keyName string, fileName string, extraExecTxArgs ...string) (string, error) {
_, file := filepath.Split(fileName)
err := tn.CopyFile(ctx, fileName, file)
if err != nil {
return "", fmt.Errorf("writing contract file to docker volume: %w", err)
}

if _, err := tn.ExecTx(ctx, keyName, "wasm", "store", path.Join(tn.HomeDir(), file), "--gas", "auto"); err != nil {
cmd := []string{"wasm", "store", path.Join(tn.HomeDir(), file), "--gas", "auto"}
cmd = append(cmd, extraExecTxArgs...)

if _, err := tn.ExecTx(ctx, keyName, cmd...); err != nil {
return "", err
}

Expand Down Expand Up @@ -955,10 +961,11 @@ func (tn *ChainNode) InstantiateContract(ctx context.Context, keyName string, co
}

// ExecuteContract executes a contract transaction with a message using it's address.
func (tn *ChainNode) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string) (txHash string, err error) {
return tn.ExecTx(ctx, keyName,
"wasm", "execute", contractAddress, message,
)
func (tn *ChainNode) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string, extraExecTxArgs ...string) (txHash string, err error) {
cmd := []string{"wasm", "execute", contractAddress, message}
cmd = append(cmd, extraExecTxArgs...)

return tn.ExecTx(ctx, keyName, cmd...)
}

// QueryContract performs a smart query, taking in a query struct and returning a error with the response struct populated.
Expand Down Expand Up @@ -992,7 +999,7 @@ func (tn *ChainNode) QueryContract(ctx context.Context, contractAddress string,
}

// StoreClientContract takes a file path to a client smart contract and stores it on-chain. Returns the contracts code id.
func (tn *ChainNode) StoreClientContract(ctx context.Context, keyName string, fileName string) (string, error) {
func (tn *ChainNode) StoreClientContract(ctx context.Context, keyName string, fileName string, extraExecTxArgs ...string) (string, error) {
content, err := os.ReadFile(fileName)
if err != nil {
return "", err
Expand All @@ -1003,7 +1010,10 @@ func (tn *ChainNode) StoreClientContract(ctx context.Context, keyName string, fi
return "", fmt.Errorf("writing contract file to docker volume: %w", err)
}

_, err = tn.ExecTx(ctx, keyName, "ibc-wasm", "store-code", path.Join(tn.HomeDir(), file), "--gas", "auto")
cmd := []string{"ibc-wasm", "store-code", path.Join(tn.HomeDir(), file), "--gas", "auto"}
cmd = append(cmd, extraExecTxArgs...)

_, err = tn.ExecTx(ctx, keyName, cmd...)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -1141,6 +1151,20 @@ func (tn *ChainNode) QueryParam(ctx context.Context, subspace, key string) (*Par
return &param, nil
}

// QueryBankMetadata returns the bank metadata of a token denomination.
func (tn *ChainNode) QueryBankMetadata(ctx context.Context, denom string) (*BankMetaData, error) {
stdout, _, err := tn.ExecQuery(ctx, "bank", "denom-metadata", "--denom", denom)
if err != nil {
return nil, err
}
var meta BankMetaData
err = json.Unmarshal(stdout, &meta)
if err != nil {
return nil, err
}
return &meta, nil
}

// DumpContractState dumps the state of a contract at a block height.
func (tn *ChainNode) DumpContractState(ctx context.Context, contractAddress string, height int64) (*DumpContractStateResponse, error) {
stdout, _, err := tn.ExecQuery(ctx,
Expand Down
23 changes: 23 additions & 0 deletions chain/cosmos/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cosmos

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func SetSDKConfig(bech32Prefix string) *sdk.Config {
var (
bech32MainPrefix = bech32Prefix
bech32PrefixAccAddr = bech32MainPrefix
bech32PrefixAccPub = bech32MainPrefix + sdk.PrefixPublic
bech32PrefixValAddr = bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator
bech32PrefixValPub = bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
bech32PrefixConsAddr = bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus
bech32PrefixConsPub = bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
)

cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(bech32PrefixAccAddr, bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(bech32PrefixValAddr, bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(bech32PrefixConsAddr, bech32PrefixConsPub)
return cfg
}
21 changes: 13 additions & 8 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ func (c *CosmosChain) QueryParam(ctx context.Context, subspace, key string) (*Pa
return c.getFullNode().QueryParam(ctx, subspace, key)
}

// QueryBankMetadata returns the metadata of a given token denomination.
func (c *CosmosChain) QueryBankMetadata(ctx context.Context, denom string) (*BankMetaData, error) {
return c.getFullNode().QueryBankMetadata(ctx, denom)
}

func (c *CosmosChain) txProposal(txHash string) (tx TxProposal, _ error) {
txResp, err := c.getTransaction(txHash)
if err != nil {
Expand All @@ -497,8 +502,8 @@ func (c *CosmosChain) txProposal(txHash string) (tx TxProposal, _ error) {
}

// StoreContract takes a file path to smart contract and stores it on-chain. Returns the contracts code id.
func (c *CosmosChain) StoreContract(ctx context.Context, keyName string, fileName string) (string, error) {
return c.getFullNode().StoreContract(ctx, keyName, fileName)
func (c *CosmosChain) StoreContract(ctx context.Context, keyName string, fileName string, extraExecTxArgs ...string) (string, error) {
return c.getFullNode().StoreContract(ctx, keyName, fileName, extraExecTxArgs...)
}

// InstantiateContract takes a code id for a smart contract and initialization message and returns the instantiated contract address.
Expand All @@ -507,8 +512,8 @@ func (c *CosmosChain) InstantiateContract(ctx context.Context, keyName string, c
}

// ExecuteContract executes a contract transaction with a message using it's address.
func (c *CosmosChain) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string) (txHash string, err error) {
return c.getFullNode().ExecuteContract(ctx, keyName, contractAddress, message)
func (c *CosmosChain) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string, extraExecTxArgs ...string) (txHash string, err error) {
return c.getFullNode().ExecuteContract(ctx, keyName, contractAddress, message, extraExecTxArgs...)
}

// QueryContract performs a smart query, taking in a query struct and returning a error with the response struct populated.
Expand All @@ -522,8 +527,8 @@ func (c *CosmosChain) DumpContractState(ctx context.Context, contractAddress str
}

// StoreClientContract takes a file path to a client smart contract and stores it on-chain. Returns the contracts code id.
func (c *CosmosChain) StoreClientContract(ctx context.Context, keyName string, fileName string) (string, error) {
return c.getFullNode().StoreClientContract(ctx, keyName, fileName)
func (c *CosmosChain) StoreClientContract(ctx context.Context, keyName string, fileName string, extraExecTxArgs ...string) (string, error) {
return c.getFullNode().StoreClientContract(ctx, keyName, fileName, extraExecTxArgs...)
}

// QueryClientContractCode performs a query with the contract codeHash as the input and code as the output
Expand Down Expand Up @@ -1054,7 +1059,7 @@ func (c *CosmosChain) Height(ctx context.Context) (uint64, error) {
// Acknowledgements implements ibc.Chain, returning all acknowledgments in block at height
func (c *CosmosChain) Acknowledgements(ctx context.Context, height uint64) ([]ibc.PacketAcknowledgement, error) {
var acks []*chanTypes.MsgAcknowledgement
err := rangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool {
err := RangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool {
found, ok := msg.(*chanTypes.MsgAcknowledgement)
if ok {
acks = append(acks, found)
Expand Down Expand Up @@ -1087,7 +1092,7 @@ func (c *CosmosChain) Acknowledgements(ctx context.Context, height uint64) ([]ib
// Timeouts implements ibc.Chain, returning all timeouts in block at height
func (c *CosmosChain) Timeouts(ctx context.Context, height uint64) ([]ibc.PacketTimeout, error) {
var timeouts []*chanTypes.MsgTimeout
err := rangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool {
err := RangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool {
found, ok := msg.(*chanTypes.MsgTimeout)
if ok {
timeouts = append(timeouts, found)
Expand Down
7 changes: 7 additions & 0 deletions chain/cosmos/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ type GenesisKV struct {
Value interface{} `json:"value"`
}

func NewGenesisKV(key string, value interface{}) GenesisKV {
return GenesisKV{
Key: key,
Value: value,
}
}

func ModifyGenesis(genesisKV []GenesisKV) func(ibc.ChainConfig, []byte) ([]byte, error) {
return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) {
g := make(map[string]interface{})
Expand Down
4 changes: 2 additions & 2 deletions chain/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type blockClient interface {
Block(ctx context.Context, height *int64) (*tmtypes.ResultBlock, error)
}

// rangeBlockMessages iterates through all a block's transactions and each transaction's messages yielding to f.
// RangeBlockMessages iterates through all a block's transactions and each transaction's messages yielding to f.
// Return true from f to stop iteration.
func rangeBlockMessages(ctx context.Context, interfaceRegistry codectypes.InterfaceRegistry, client blockClient, height uint64, done func(sdk.Msg) bool) error {
func RangeBlockMessages(ctx context.Context, interfaceRegistry codectypes.InterfaceRegistry, client blockClient, height uint64, done func(sdk.Msg) bool) error {
h := int64(height)
block, err := client.Block(ctx, &h)
if err != nil {
Expand Down
Loading

0 comments on commit c35a44f

Please sign in to comment.