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

πŸ–ŒοΈ Minor publishing code syntax #1099

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/build/guides/testing/unit-tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Unit tests are small tests that test one piece of functionality within a contrac

## How to Write Unit Tests

The following is an example of a unit test, written to test the [increment contract]. The contract has an `increment` function, that increases a counter value by one on every invocation. The following test invokes that contract's function several times, and checks that the value increases by one.
The following is an example of a unit test, written to test the [increment contract](https://github.com/stellar/soroban-examples/blob/main/increment/src/lib.rs). The contract has an `increment` function, that increases a counter value by one on every invocation. The following test invokes that contract's function several times, and checks that the value increases by one.

```rust
#![cfg(test)]
Expand Down Expand Up @@ -71,4 +71,12 @@ The `Env` created at the beginning of the test is not a simulation of the Soroba

:::

[increment contract]: https://github.com/stellar/soroban-examples/blob/main/increment/src/lib.rs

It's a simple test, but it's a complete test. There's a full environment setup, used, and torn down in the test, and it happens fast. The Rust test harness runs all the tests for a contract in parallel and each will have its own isolated contract environment.

Most tests, even integration tests and fuzz tests, will look very similar to this unit test. They'll do four things:

1. Create an environment, the `Env`.
2. Register the contract(s) to be tested.
3. Invoke functions using a client.
4. Assert the outcome.
99 changes: 48 additions & 51 deletions docs/tokens/publishing-asset-info.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,27 @@ You should also use the `set_options` operation to set the home domain on your i

```nginx title="Configure stellar.toml for nginx"
server {

server_name my.example.com;
root /var/www/my.example.com;

location = /.well-known/stellar.toml {
types { } default_type "text/plain; charset=utf-8";
allow all;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
}

// CertBot SSL configuration
// ...
server_name my.example.com;
root /var/www/my.example.com;

location = /.well-known/stellar.toml {
types { } default_type "text/plain; charset=utf-8";
allow all;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
}

// CertBot SSL configuration
// ...
}
```

Expand Down Expand Up @@ -208,33 +207,31 @@ server = Server(horizon_url="https://horizon-testnet.stellar.org")
network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE

# Keys for accounts to issue and receive the new asset
issuing_keypair = Keypair.from_secret(
"SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4"
)
issuing_keypair = Keypair.from_secret("SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4")
issuing_public = issuing_keypair.public_key


# Transactions require a valid sequence number that is specific to this account.
# We can fetch the current sequence number for the source account from Horizon.
issuing_account = server.load_account(issuing_public)

transaction = (
TransactionBuilder(
source_account=issuing_account,
network_passphrase=network_passphrase,
base_fee=100,
)
.append_set_options_op(
home_domain="yourdomain.com"
)
.build()
TransactionBuilder(
source_account = issuing_account,
network_passphrase = network_passphrase,
base_fee = 100,
)
.append_set_options_op(
home_domain = "yourdomain.com"
)
.build()
)
transaction.sign(issuing_keypair)

try:
transaction_resp = server.submit_transaction(transaction)
print(f"Transaction Resp:\n{transaction_resp}")
transaction_resp = server.submit_transaction(transaction)
print(f"Transaction Resp:\n{transaction_resp}")
except BaseHorizonError as e:
print(f"Error: {e}")
print(f"Error: {e}")
```

```java
Expand Down Expand Up @@ -265,19 +262,19 @@ func main() {
}

// Build the transaction
tx, err := txnbuild.NewTransaction(
txnbuild.TransactionParams{
SourceAccount: &issuingAccount,
IncrementSequenceNum: true,
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{TimeBounds: txnbuild.NewTimeout(100)},
Operations: []txnbuild.Operation{
&txnbuild.SetOptions{
HomeDomain: "yourdomain.com",
},
},
},
)
tx, err := txnbuild.NewTransaction(
txnbuild.TransactionParams{
SourceAccount: &issuingAccount,
IncrementSequenceNum: true,
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{TimeBounds: txnbuild.NewTimeout(100)},
Operations: []txnbuild.Operation{
&txnbuild.SetOptions{
HomeDomain: "yourdomain.com",
},
},
},
)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading