-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cli): Add NEAR smoketest (#1255)
- Loading branch information
Showing
7 changed files
with
13,303 additions
and
5,875 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,12 @@ | ||
/* grainc-flags --no-gc --no-bulk-memory */ | ||
|
||
import WasmI32 from "runtime/unsafe/wasmi32" | ||
import WasmI64 from "runtime/unsafe/wasmi64" | ||
import Env from "./nearEnv" | ||
|
||
export let hello = () => { | ||
let value = "Hello, World!" | ||
let length = WasmI64.load32U(WasmI32.fromGrain(value), 4n) | ||
let ptr = WasmI64.extendI32U(WasmI32.add(WasmI32.fromGrain(value), 8n)) | ||
Env.valueReturn(length, ptr) | ||
} |
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,31 @@ | ||
const path = require("path"); | ||
|
||
// NOTE: | ||
// This test suite exists to ensure wasm output does not contain multivalue functions. | ||
// If no multivalue functions exist, Grain smart contracts should run without issue. | ||
|
||
let worker; | ||
afterAll(async () => { | ||
await worker?.tearDown(); | ||
}); | ||
|
||
describe("Runs in NEAR sandbox", () => { | ||
jest.setTimeout(60_000); | ||
let Worker; | ||
try { | ||
Worker = require("near-workspaces").Worker; | ||
} catch (err) { | ||
// no-op | ||
} | ||
// near-workspaces is optional, so if it's not installed, we can skip tests | ||
const testIf = !Worker ? test.skip : test; | ||
testIf("it should not produce wasm multivalue function", async () => { | ||
worker = await Worker.init(); | ||
const root = worker.rootAccount; | ||
const contract = await root.createAndDeploy( | ||
"grain-near-multivalue-test", | ||
path.join(__dirname, "index.gr.wasm") | ||
); | ||
expect(await contract.view("hello")).toEqual("Hello, World!"); | ||
}); | ||
}); |
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,28 @@ | ||
/* grainc-flags --no-gc --no-bulk-memory */ | ||
|
||
export foreign wasm storage_read: ( | ||
WasmI64, | ||
WasmI64, | ||
WasmI64 | ||
) -> WasmI64 as storageRead from "env" | ||
export foreign wasm storage_write: ( | ||
WasmI64, | ||
WasmI64, | ||
WasmI64, | ||
WasmI64, | ||
WasmI64 | ||
) -> WasmI64 as storageWrite from "env" | ||
export foreign wasm storage_has_key: ( | ||
WasmI64, | ||
WasmI64 | ||
) -> WasmI64 as storageHasKey from "env" | ||
|
||
export foreign wasm read_register: ( | ||
WasmI64, | ||
WasmI64 | ||
) -> Void as readRegister from "env" | ||
|
||
export foreign wasm value_return: ( | ||
WasmI64, | ||
WasmI64 | ||
) -> Void as valueReturn from "env" |
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,9 @@ | ||
export let fd_write: (WasmI32, WasmI32, WasmI32, WasmI32) -> WasmI32 = | ||
( | ||
fd, | ||
iovs, | ||
iovs_len, | ||
nwritten, | ||
) => { | ||
0n | ||
} |
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
Oops, something went wrong.