Skip to content

Commit

Permalink
collections use dict
Browse files Browse the repository at this point in the history
  • Loading branch information
volovyks committed Jun 2, 2022
1 parent c7fdd0b commit 0312177
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 158 deletions.
36 changes: 18 additions & 18 deletions tests/__tests__/lookup-map.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ test.afterEach(async t => {
test('LookupMap set() get()', async t => {
const { ali, jsvm, testContract } = t.context.accounts;
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', { key: 'hello' })),
null
);
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'containsKey', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'containsKey', { key: 'hello' })),
false
);

await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', ['hello', 'world']), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', { key: 'hello', value: 'world' }), { attachedDeposit: '100000000000000000000000' });

t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', { key: 'hello' })),
'world'
);
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'containsKey', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'containsKey', { key: 'hello' })),
true
);
});
Expand All @@ -68,50 +68,50 @@ test('LookupMap set() get()', async t => {
test('LookupMap update, remove', async t => {
const { ali, jsvm, testContract } = t.context.accounts;

await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', ['hello', 'world']), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', ['hello1', 'world0']), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', { key: 'hello', value: 'world' }), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', { key: 'hello1', value: 'world0' }), { attachedDeposit: '100000000000000000000000' });

// update a value, len shouldn't change
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', ['hello1', 'world1']), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', { key: 'hello1', value: 'world1' }), { attachedDeposit: '100000000000000000000000' });
// update should have effect
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', ['hello1'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', { key: 'hello1' })),
'world1'
);
// not update key should not changed
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', { key: 'hello' })),
'world'
);
// remove non existing element should not error
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'remove', ['hello3']), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'remove', { key: 'hello3' }), { attachedDeposit: '100000000000000000000000' });
// remove existing key should work
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'remove', ['hello1']));
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'remove', { key: 'hello1' }));
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'containsKey', ['hello1'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'containsKey', { key: 'hello1' })),
false
);
// not removed key should not affected
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', { key: 'hello' })),
'world'
);
});

test('LookupMap extend', async t => {
const { ali, jsvm, testContract } = t.context.accounts;

await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'extend', [[['hello', 'world'], ['hello1', 'world1'], ['hello2', 'world2']]]), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'extend', { kvs: [['hello', 'world'], ['hello1', 'world1'], ['hello2', 'world2']] }), { attachedDeposit: '100000000000000000000000' });
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', { key: 'hello' })),
'world'
);
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', ['hello1'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', { key: 'hello1' })),
'world1'
);
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', ['hello2'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'get', { key: 'hello2' })),
'world2'
);
})
26 changes: 13 additions & 13 deletions tests/__tests__/lookup-set.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ test.afterEach(async t => {
test('LookupSet set() contains()', async t => {
const { ali, jsvm, testContract } = t.context.accounts;
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', { key: 'hello' })),
false
);

await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', ['hello']), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', { key: 'hello' }), { attachedDeposit: '100000000000000000000000' });

t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', { key: 'hello' })),
true
);
});
Expand All @@ -60,38 +60,38 @@ test('LookupSet set() contains()', async t => {
test('LookupSet remove', async t => {
const { ali, jsvm, testContract } = t.context.accounts;

await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', ['hello']), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', ['hello1']), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', { key: 'hello' }), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'set', { key: 'hello1' }), { attachedDeposit: '100000000000000000000000' });

// remove non existing element should not error
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'remove', ['hello3']), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'remove', { key: 'hello3' }), { attachedDeposit: '100000000000000000000000' });
// remove existing key should work
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'remove', ['hello1']));
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'remove', { key: 'hello1' }));
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', ['hello1'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', { key: 'hello1' })),
false
);
// not removed key should not affected
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', { key: 'hello' })),
true
);
});

test('LookupSet extend', async t => {
const { ali, jsvm, testContract } = t.context.accounts;

await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'extend', [['hello', 'world', 'hello1']]), { attachedDeposit: '100000000000000000000000' });
await ali.call(jsvm, 'call_js_contract', encodeCall(testContract.accountId, 'extend', { keys: ['hello', 'world', 'hello1'] }), { attachedDeposit: '100000000000000000000000' });
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', ['hello'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', { key: 'hello' })),
true
);
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', ['hello1'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', { key: 'hello1' })),
true
);
t.is(
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', ['world'])),
await jsvm.view('view_js_contract', encodeCall(testContract.accountId, 'contains', { key: 'world' })),
true
);
})
Loading

0 comments on commit 0312177

Please sign in to comment.