Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests of XCS with CW20s #4941

Merged
merged 5 commits into from
May 4, 2023
Merged

Added tests of XCS with CW20s #4941

merged 5 commits into from
May 4, 2023

Conversation

nicolaslara
Copy link
Contributor

What is the purpose of the change

Test that XCS works with cw20s. This depends on CosmWasm/cw-plus#868.

On mainnet, the ics20 contract would need to be updated to use those changes

Brief Changelog

Added tests using cw20s

Testing and Verifying

tests pass

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? (yes / no)
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (yes / no)
  • How is the feature or change documented? (not applicable / specification (x/<module>/spec/) / Osmosis docs repo / not documented)

@nicolaslara nicolaslara added V:state/compatible/no_backport State machine compatible PR, depends on prior breaks no-changelog labels Apr 17, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2023

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only nits! :)

Comment on lines +569 to +572
case CW20toA:
sender = suite.chainB
case AtoCW20:
sender = suite.chainA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be helpful for readability if we call this B-CW20 so the reviewer knows the CW chain is analogous to B

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can rename it, but we can't use -. Any preference between BCW20ToA, B_CW20ToA or Bcw20ToA? They all look ugly to me

Comment on lines +39 to +41
if len(memo) == 0 {
memo = "\"\""
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my knowledge, why is the memo required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the empty string would Sprintf to nothing and then the json would say "memo": } which is invalid. We could remove the memo key altogether, but thought this was cleaner than two srpintfs

Comment on lines 93 to 97
x, ok := sdk.NewIntFromString(res.Get("balance").String())
if !ok {
panic("could not parse balance")
}
return x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we change x to bal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


// Test that the cw20-ics20 contract can be instantiated and used to send tokens to chainA
func (suite *HooksTestSuite) TestCW20ICS20() {
suite.Require().Equal("stake", sdk.DefaultBondDenom) // hardcodiing "stake" for simplicity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand, wouldn't it just be better to utilize sdk.DefaultBondDenom instead of explicitly using stake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right. There were other places where "stake" was being used and I was too lazy to change it. Fixed now

suite.coordinator.Setup(path)

osmosisAppB := chainB.GetOsmosisApp()
//osmosisAppA := chainA.GetOsmosisApp()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//osmosisAppA := chainA.GetOsmosisApp()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

osmosisAppB := chainB.GetOsmosisApp()
//osmosisAppA := chainA.GetOsmosisApp()

// Send some cwtoken tokens from B to A via the new path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Send some cwtoken tokens from B to A via the new path
// Send some cwtoken tokens from B to A via the new path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

chainB.SenderAccount.GetAddress(),
)
xcsMsg := fmt.Sprintf(`{"wasm": {"contract": "%s", "msg": %s } }`, crosschainAddr, swapMsg)
serializedMemo, _ := json.Marshal(xcsMsg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we are nulling err check here or if this is something else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we're ignoring the error cause that should never fail (it's marshalling a hardcoded string (but I've changed it to checking the error to make it less confusing)

Comment on lines +175 to +177
// Check that the receiver has more cw20 tokens than before
newCw20Balance := suite.getCW20Balance(chainB, cw20Addr, receiver2)
suite.Require().Greater(newCw20Balance.Int64(), cw20Balance.Int64())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we determine the exact amount expected here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it, but since this depends on the underlying pool, any future changes to how pools work or the params we're using for the tests would make this fail. So I figure this was safer. Happy to change it if you think that's better

@nicolaslara nicolaslara merged commit b933897 into main May 4, 2023
@nicolaslara nicolaslara deleted the nicolas/xcs-cw20 branch May 4, 2023 07:04
pysel pushed a commit that referenced this pull request Jun 6, 2023
* added initial cw20 testing

* fixed serialization

* added route and fixed pool discrepancies

* added cw20 tests

* fixed nits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V:state/compatible/no_backport State machine compatible PR, depends on prior breaks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants