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
yarn installif that's more your style)
- 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
My Account. Navigate to the
Paymentstab Note: If you are a first-time user, you may be prompted to generate an Oasis-managed wallet, which you should do. Your wallet is what serves as your identity and enables you to interact with Oasis services.
- Make sure you are in a secure location, and then Click to reveal.
This will reveal your private key, which is used to control your wallet. You must never lose your private key nor share it with anyone—unless, of course, you want to lose control of your wallet!
- Give your local toolchain access to your wallet by running
oasis config profile.default.private_key "<private key>"
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!