diff --git a/docs/build/guides/testing/unit-tests.mdx b/docs/build/guides/testing/unit-tests.mdx index 0deaab4b7..badc858e4 100644 --- a/docs/build/guides/testing/unit-tests.mdx +++ b/docs/build/guides/testing/unit-tests.mdx @@ -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)] @@ -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. diff --git a/docs/tokens/publishing-asset-info.mdx b/docs/tokens/publishing-asset-info.mdx index 0466e224a..fe18a0bec 100644 --- a/docs/tokens/publishing-asset-info.mdx +++ b/docs/tokens/publishing-asset-info.mdx @@ -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 + // ... } ``` @@ -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 @@ -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) }