In this guide we will take you through setting up your Oasis dev environment, testing a simple Rust service using cargo, testing the same service using a locally running blockchain, and finally testing it using our Devnet 2.0.
Set Up the Oasis SDK
Install the Oasis Toolchain
curl --proto '=https' --tlsv1.2 -sSL https://get.oasis.dev | python
Alternatively, pipe into
python - --help to see installation options.
Unit Test the "Hello World" Service Using Cargo
git clone https://github.com/oasislabs/tutorials
oasis test -- --nocapture
The test will do the following:
- Retrieve "Hello World!" in Slovenian
- Attempt to retrieve "Hello World!" in Samoan, but fail because it doesn't exist
- Attempt to insert a duplicate greeting (this will fail)
- Insert "Hello World!" in Samoan
- Retrieve "Hello World!"" successfully in Samoan
You should see the following console output:
running 1 test In Slovenian: "Pozdravljen, svet!" In Samoan: None Adding "Zeno World!" for "en" Err(DuplicateEntry) Adding "alofa fiafia i le lalolagi!" for "ws" In Samoan: "alofa fiafia i le lalolagi!" test tests::test_paths ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Great! Now that the tests pass, it's time build the service for deployment and test it on the local chain.
Integration Test Using the Local Chain
- Install app dependencies using
- In a separate terminal, run the local chain using
You can now test on the local chain using
Note that the
app tests will run when in a subdirectory of
app. You will see the following output,
PASS test/service.spec.ts (5.965s) HelloWorld Test ✓ deployed (2ms) ✓ known greeting (409ms) ✓ insert new greeting in Samoan (400ms) Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total
Deploy on Devnet 2.0
- Login to the Oasis developer dashboard and visit
- Make sure you are in a secure location, and then Click to reveal your API token in the
Credentialssection of the
Account Infotab. You must never lose your API token nor share it with anyone!
- Give your local toolchain access to deploy services on your behalf by running the following command, which will begin to read your credential from stdin.
You should then paste your credential in and hit enter.
oasis config profile.default.credential -
You can now deploy your service to Devnet 2.0, using
When you run that command, with any luck, you'll see something like the following:
Deploying hello-world ... Deployed HelloWorld at 0xf8b476862dd4bcaaabb988aa5a459d95e319ac0e
You can now point an app at
0xf8b476862dd4bcaaabb988aa5a459d95e319ac0e using the client's Service.at constructor and interact with the spiffy decentralized backend you just deployed!