Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify datastore_manipulation test to add prefix to getKeys and getKeysOf #32

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions assembly/massa/datastore_manipulations/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,46 @@
* which is ready to be send on Massa network node!
**/

import { Storage, getKeys, getKeysOf, generateEvent, Context, print } from "@massalabs/massa-as-sdk";
import {Storage, getKeys, getKeysOf, generateEvent, Context, print} from "@massalabs/massa-as-sdk";

export function main(_args: string): void {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend writing a second test and keep this one as simple as possible :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated the test in two halfs with a comment in between, tell me if that's OK for you


// Simple test
const key1: StaticArray<u8> = [1, 0, 4, 255];
const key2: StaticArray<u8> = [2, 0, 254, 255];
const key2: StaticArray<u8> = [15, 230, 12, 2];
const value1: StaticArray<u8> = [21, 0, 49];
const value2: StaticArray<u8> = [42, 0, 48];
Storage.set(key1, value1);
Storage.set(key2, value2);
Storage.del(key2);

let keys = getKeys();
let keys = getKeys([]);
let msg = `keys: ${keys}`;
// print(msg);
generateEvent(msg);
assert(keys.length == 1);

let addr_ = Context.callee();
let addr = addr_.toString();
let keys2 = getKeysOf(addr);
let addr = Context.callee().toString();
let keys2 = getKeysOf(addr, []);
let msg2 = `keys2: ${keys2}`;
// print(msg2);
generateEvent(msg2);
assert(keys2.length == 2);

// Test using key prefixes
const key3: StaticArray<u8> = [2, 0, 254, 255];
const value3: StaticArray<u8> = [5, 12, 241];
Storage.set(key3, value3);

let keys_f = getKeys([2, 0]);
let msg_f = `keys_f: ${keys_f}`;
// print(msg_f);
generateEvent(msg_f);
assert(keys_f.length == 1);

let keys2_f = getKeysOf(addr, [1, 0, 4]);
let msg2_f = `keys2_f: ${keys2_f}`;
// print(msg2_f);
generateEvent(msg2_f);
assert(keys2_f.length == 1);
}