-
Notifications
You must be signed in to change notification settings - Fork 136
Add stellar token transfer for SEP-41 and Stellar Asset Contracts
#2644
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0e96d0f
Add token transfer command for SEP-41 and asset contracts.
fnando 54360ee
Reject negative token transfer amounts.
fnando 1b52fd1
Accept contract addresses as token transfer destinations.
fnando 9451463
Always submit token transfers instead of simulating.
fnando 33f8bfd
Fail loudly when SAC deploy errors in tests.
fnando 80d0e8d
Reject muxed source accounts with a clear error.
fnando 9ee7a6b
Resolve native token target through the built-in alias.
fnando File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -14,5 +14,6 @@ mod ledger; | |
| mod network; | ||
| mod secure_store; | ||
| mod snapshot; | ||
| mod token; | ||
| mod tx; | ||
| mod util; | ||
This file contains hidden or 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,93 @@ | ||
| pub mod transfer; | ||
|
|
||
| use soroban_test::{AssertExt, TestEnv}; | ||
|
|
||
| /// Establish (and auto-authorize) a trustline from `source` to `asset`. | ||
| pub fn add_trustline(sandbox: &TestEnv, source: &str, asset: &str) { | ||
| sandbox | ||
| .new_assert_cmd("tx") | ||
| .args(["new", "change-trust", "--line", asset, "--source", source]) | ||
| .assert() | ||
| .success(); | ||
| } | ||
|
|
||
| /// Pay `amount` of `asset` from its issuer to `destination`. | ||
| pub fn issuer_pays(sandbox: &TestEnv, issuer: &str, destination: &str, asset: &str, amount: i128) { | ||
| sandbox | ||
| .new_assert_cmd("tx") | ||
| .args([ | ||
| "new", | ||
| "payment", | ||
| "--destination", | ||
| destination, | ||
| "--asset", | ||
| asset, | ||
| "--amount", | ||
| &amount.to_string(), | ||
| "--source", | ||
| issuer, | ||
| ]) | ||
| .assert() | ||
| .success(); | ||
| } | ||
|
|
||
| /// Deploy the Stellar Asset Contract for `asset`, tolerating the case where a | ||
| /// prior run already deployed it (the SAC is global to the network). | ||
| pub fn deploy_sac(sandbox: &TestEnv, asset: &str, source: &str) { | ||
| let output = sandbox | ||
| .new_assert_cmd("contract") | ||
| .args([ | ||
| "asset", | ||
| "deploy", | ||
| "--asset", | ||
| asset, | ||
| "--source-account", | ||
| source, | ||
| ]) | ||
| .output() | ||
| .expect("failed to run contract asset deploy"); | ||
|
|
||
| // A clean deploy succeeds; the only failure we tolerate is the SAC already | ||
| // existing on this (persistent) network. Any other failure is a real bug — | ||
| // surface the captured stderr instead of swallowing it and misdirecting the | ||
| // failure two steps downstream. | ||
| if !output.status.success() { | ||
| let stderr = String::from_utf8_lossy(&output.stderr); | ||
| assert!( | ||
| stderr.contains("contract already exists"), | ||
| "contract asset deploy failed: {stderr}" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// The contract id of the SAC for `asset`. | ||
| pub fn sac_id(sandbox: &TestEnv, asset: &str) -> String { | ||
| sandbox | ||
| .new_assert_cmd("contract") | ||
| .args(["id", "asset", "--asset", asset]) | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str() | ||
| } | ||
|
|
||
| /// Read a token's balance for `account` through its Stellar Asset Contract, | ||
| /// returning the raw stroop amount. | ||
| pub fn sac_balance(sandbox: &TestEnv, contract_id: &str, account: &str) -> i128 { | ||
| let stdout = sandbox | ||
| .new_assert_cmd("contract") | ||
| .args([ | ||
| "invoke", | ||
| "--id", | ||
| contract_id, | ||
| "--source-account", | ||
| "test", | ||
| "--", | ||
| "balance", | ||
| "--id", | ||
| account, | ||
| ]) | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
| stdout.trim().trim_matches('"').parse().unwrap() | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.