Skip to content

Commit

Permalink
Merge branch 'v7' into mergify/bp/v7/pr-805
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups authored Oct 16, 2023
2 parents 8fcfe5a + 82665fe commit e554e96
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 1 deletion.
14 changes: 14 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,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
5 changes: 5 additions & 0 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,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 Down
104 changes: 104 additions & 0 deletions chain/cosmos/tokenfactory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package cosmos

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

"github.com/strangelove-ventures/interchaintest/v7/ibc"
)

// TokenFactoryCreateDenom creates a new tokenfactory token in the format 'factory/accountaddress/name'.
// This token will be viewable by standard bank balance queries and send functionality.
// Depending on the chain parameters, this may require a lot of gas (Juno, Osmosis) if the DenomCreationGasConsume param is enabled.
// If not, the default implementation cost 10,000,000 micro tokens (utoken) of the chain's native token.
func TokenFactoryCreateDenom(c *CosmosChain, ctx context.Context, user ibc.Wallet, denomName string, gas uint64) (string, string, error) {
cmd := []string{"tokenfactory", "create-denom", denomName}

if gas != 0 {
cmd = append(cmd, "--gas", strconv.FormatUint(gas, 10))
}

txHash, err := c.getFullNode().ExecTx(ctx, user.KeyName(), cmd...)
if err != nil {
return "", "", err
}

return "factory/" + user.FormattedAddress() + "/" + denomName, txHash, nil
}

// TokenFactoryBurnDenom burns a tokenfactory denomination from the holders account.
func TokenFactoryBurnDenom(c *CosmosChain, ctx context.Context, keyName, fullDenom string, amount uint64) (string, error) {
coin := strconv.FormatUint(amount, 10) + fullDenom
return c.getFullNode().ExecTx(ctx, keyName,
"tokenfactory", "burn", coin,
)
}

// TokenFactoryBurnDenomFrom burns a tokenfactory denomination from any other users account.
// Only the admin of the token can perform this action.
func TokenFactoryBurnDenomFrom(c *CosmosChain, ctx context.Context, keyName, fullDenom string, amount uint64, fromAddr string) (string, error) {
return c.getFullNode().ExecTx(ctx, keyName,
"tokenfactory", "burn-from", fromAddr, convertToCoin(amount, fullDenom),
)
}

// TokenFactoryChangeAdmin moves the admin of a tokenfactory token to a new address.
func TokenFactoryChangeAdmin(c *CosmosChain, ctx context.Context, keyName, fullDenom, newAdmin string) (string, error) {
return c.getFullNode().ExecTx(ctx, keyName,
"tokenfactory", "change-admin", fullDenom, newAdmin,
)
}

// TokenFactoryForceTransferDenom force moves a token from 1 account to another.
// Only the admin of the token can perform this action.
func TokenFactoryForceTransferDenom(c *CosmosChain, ctx context.Context, keyName, fullDenom string, amount uint64, fromAddr, toAddr string) (string, error) {
return c.getFullNode().ExecTx(ctx, keyName,
"tokenfactory", "force-transfer", convertToCoin(amount, fullDenom), fromAddr, toAddr,
)
}

// TokenFactoryMintDenom mints a tokenfactory denomination to the admins account.
// Only the admin of the token can perform this action.
func TokenFactoryMintDenom(c *CosmosChain, ctx context.Context, keyName, fullDenom string, amount uint64) (string, error) {
return c.getFullNode().ExecTx(ctx, keyName,
"tokenfactory", "mint", convertToCoin(amount, fullDenom),
)
}

// TokenFactoryMintDenomTo mints a token to any external account.
// Only the admin of the token can perform this action.
func TokenFactoryMintDenomTo(c *CosmosChain, ctx context.Context, keyName, fullDenom string, amount uint64, toAddr string) (string, error) {
return c.getFullNode().ExecTx(ctx, keyName,
"tokenfactory", "mint-to", toAddr, convertToCoin(amount, fullDenom),
)
}

// TokenFactoryMetadata sets the x/bank metadata for a tokenfactory token. This gives the token more detailed information to be queried
// by frontend UIs and other applications.
// Only the admin of the token can perform this action.
func TokenFactoryMetadata(c *CosmosChain, ctx context.Context, keyName, fullDenom, ticker, description string, exponent uint64) (string, error) {
return c.getFullNode().ExecTx(ctx, keyName,
"tokenfactory", "modify-metadata", fullDenom, ticker, description, strconv.FormatUint(exponent, 10),
)
}

// TokenFactoryGetAdmin returns the admin of a tokenfactory token.
func TokenFactoryGetAdmin(c *CosmosChain, ctx context.Context, fullDenom string) (*QueryDenomAuthorityMetadataResponse, error) {
res := &QueryDenomAuthorityMetadataResponse{}
stdout, stderr, err := c.getFullNode().ExecQuery(ctx, "tokenfactory", "denom-authority-metadata", fullDenom)
if err != nil {
return nil, fmt.Errorf("failed to query tokenfactory denom-authority-metadata: %w\nstdout: %s\nstderr: %s", err, stdout, stderr)
}

if err := json.Unmarshal(stdout, res); err != nil {
return nil, err
}

return res, nil
}

func convertToCoin(amount uint64, denom string) string {
return strconv.FormatUint(amount, 10) + denom
}
26 changes: 26 additions & 0 deletions chain/cosmos/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,29 @@ type BinaryBuildInformation struct {
BuildDeps []BuildDependency `json:"build_deps"`
CosmosSdkVersion string `json:"cosmos_sdk_version"`
}

type BankMetaData struct {
Metadata struct {
Description string `json:"description"`
DenomUnits []struct {
Denom string `json:"denom"`
Exponent int `json:"exponent"`
Aliases []string `json:"aliases"`
} `json:"denom_units"`
Base string `json:"base"`
Display string `json:"display"`
Name string `json:"name"`
Symbol string `json:"symbol"`
URI string `json:"uri"`
URIHash string `json:"uri_hash"`
} `json:"metadata"`
}

type QueryDenomAuthorityMetadataResponse struct {
AuthorityMetadata DenomAuthorityMetadata `protobuf:"bytes,1,opt,name=authority_metadata,json=authorityMetadata,proto3" json:"authority_metadata" yaml:"authority_metadata"`
}

type DenomAuthorityMetadata struct {
// Can be empty for no admin, or a valid address
Admin string `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty" yaml:"admin"`
}
43 changes: 43 additions & 0 deletions docs/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others’ private information, such as a physical or electronic address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies within all project spaces, and it also applies when an individual is representing the project or its community in public spaces. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at <[email protected]>. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project’s leadership.

## Attribution

This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>
91 changes: 91 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Contributing to Interchaintest

Welcome to the Interchaintest project! We're thrilled that you're interested in contributing. Interchaintest is an end-to-end testing framework designed to empower the IBC (Inter-Blockchain Communication) ecosystem, and your contributions can help make it even more robust and valuable for networks and developers alike.

## Table of Contents

- [Code of Conduct](#code-of-conduct)
- [Getting Started](#getting-started)
- [Contributing Guidelines](#contributing-guidelines)
- [Issues](#issues)
- [Pull Requests](#pull-requests)
- [Responsibilities of a PR Reviewer](#responsibilities-of-a-pr-reviewer)

## Code of Conduct

Please review our [Code of Conduct](./CODE_OF_CONDUCT.md) to understand the standards and expectations for participating in our community. We are committed to fostering a welcoming and inclusive environment.

## Getting Started

Before you start contributing, make sure you have the following prerequisites installed:

- [Go](https://golang.org/dl/)
- [Docker](https://www.docker.com/get-started)
- [VSCode (recommended editor)](https://code.visualstudio.com/)

To get started, follow these steps:

1. Fork the Interchaintest repository to your own GitHub account.

2. Clone your forked repository to your local machine:

```sh
git clone https://github.com/<Username>/interchaintest.git
```

3. Crate a new branch on your fork

```sh
git checkout -b name/broad-description-of-feature
```

4. Make your changes and commit them with descriptive commit messages.

5. Test your changes locally with `go test ./...`, or by running the specific test affecting your feature or fix.

6. Push your changes to your github forked repository

```sh
git push origin name/broad-description-of-feature
```

7. Create a pull request (PR) against the main branch of the Interchaintest repository. If the PR is still a work-in-progress, please mark the PR as draft.

## Contributing Guidelines

- Adhere to the project's coding style and conventions.
- Write clear and concise commit messages and PR descriptions.
- Be responsive to feedback and collaborate with others.
- Document code and include appropriate tests.
- For documentation or typo fixes, submit separate PRs.
- Keep PRs focused on a single issue or feature.
## Issues
We welcome bug reports, feature requests, and other contributions to our project. To open an issue, please follow these guidelines:
1) Search existing issues: Before opening a new issue, please search existing issues to ensure that is not a duplicates.
2) Provide a clear and descriptive title: This helps others understand the nature of the issue at a glance.
3) Provide detailed information: In the issue description, clearly state the purpose of the issue and follow the guidelines of the issue template
4) A maintainer will take care of assigning the appropriate labels to your issue, if applicable.
## Pull requests
In almost all cases, you should target branch `main` with your work. In the event it spans multiple releases, we will backport to the previous release branch as well. This can be found in our [READMEs maintained branches](./README.md#maintained-branches).
For internal branches, branch names should be prefixed with the author's name followed by a short description of the feature, eg. `name/feature-x`.

Pull requests are made against `main` and are squash-merged into main after approval. All CI pipeline test must pass for this to be the case.

## Responsibilities of a PR Reviewer

As a PR reviewer, your primary responsibility is to guide the PR through to completion. This entails not only identifying and addressing issues within the PR but also taking a leadership role in resolving any decisions necessary for the PR to be merged successfully.

In cases where you are assigned as a reviewer for a PR that pertains to an unfamiliar part of the codebase, it's perfectly acceptable to delegate the review to a more knowledgeable colleague, provided they are willing to assume that responsibility. This ensures that the PR receives expert attention and increases the likelihood of its successful merging. Collaboration and teamwork are key in maintaining code quality and project progress.

---

We appreciate your contributions and look forward to working with you to make Interchaintest a valuable resource for the IBC community. If you have any questions or need assistance, feel free to reach out to the maintainers, community members, or <[email protected]>.
Loading

0 comments on commit e554e96

Please sign in to comment.