-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec4da57
commit e736d58
Showing
2 changed files
with
30 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,15 @@ | ||
A minimal environment for simulation of WASM smart contracts | ||
============================================================ | ||
|
||
Sometimes spinning up near-workspaces might not be needed if you're only going to simulate view methods or storage. By mocking the NEAR environment imports you can easily and fast spin up a smart contract runner for such simple use cases. | ||
|
||
Given you have a simple contract `my-contract.wasm` that exports a view function named `hello`, and you can provide `name` as an argument, you can test that it returns a given value like shown in the example below. | ||
|
||
```javascript | ||
import { getContractInstanceExports } from "./contract-runner.js"; | ||
|
||
const { exports, nearenv } = await getContractInstanceExports(await readFile('./my-contract.wasm')); | ||
nearenv.set_args({ name: 'peter' }); | ||
exports.hello(); | ||
expect(nearenv.latest_return_value).to.equal('hello peter'); | ||
``` |