Skip to content

Commit

Permalink
Add test for raw setter/getter methods in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
KiChjang committed Sep 21, 2020
1 parent c1dbf6c commit 28b23ff
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nearcore-tests/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
TESTS=(getDefaultValue mapTestsWithArray base58Test base64Test logTest storageStringRoundtripTest storageBytesRoundtripTest storageGenericGetSetRoundtripTest mapTests mapTestsWithPrimitices vectorTests dequeTests promiseTests mathTests)
TESTS=(getDefaultValue mapTestsWithArray base58Test base64Test logTest storageStringRoundtripTest storageBytesRoundtripTest storageGenericGetSetRoundtripTest storageRawRoundtripTest mapTests mapTestsWithPrimitices vectorTests dequeTests promiseTests mathTests)
DISABLED_TESTS=(contextTests)

[[ -e /tmp/main.wasm ]] && rm /tmp/main.wasm
Expand Down
36 changes: 36 additions & 0 deletions sdk/assembly/__tests__/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ContractPromise,
math,
ContractPromiseBatch,
util,
} from "..";
import { TextMessage } from "./model";
import {
Expand Down Expand Up @@ -170,6 +171,41 @@ export function storageGenericGetSetRoundtripTest(): void {
);
}

export function storageRawRoundtripTest(): void {
logging.log("storageRawRoundtripTest");

storage.setString("message1", "Hello World");
storage.read_raw("message1", 0);
const stringRegGet = util.read_register_string(0);
assert(
stringRegGet == "Hello World",
"Incorrect string value from register"
);

storage.write_raw("message2", 0);
const stringGetResult = storage.getString("message2");
assert(
stringGetResult == "Hello World",
"Incorrect string value for roundtrip"
);

const bytes = _testBytes();
storage.setBytes("bytes1", bytes);
storage.read_raw("bytes1", 0);
const bytesRegGet = util.read_register(0);
assert(
_arrayEqual(bytes, bytesRegGet),
"Incorrect bytes value from register"
);

storage.write_raw("bytes2", 0);
const bytesGetResult = storage.getBytes("bytes2");
assert(
_arrayEqual(bytes, bytesGetResult),
"Incorrect bytes value for roundtrip"
);
}

export function mapTests(): void {
logging.log("mapTests");
// empty map
Expand Down

0 comments on commit 28b23ff

Please sign in to comment.