Skip to content

Commit

Permalink
/tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
volovyks committed Aug 31, 2022
1 parent 5d60320 commit 714f783
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 118 deletions.
5 changes: 0 additions & 5 deletions tests/__tests__/bytes.ava.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Worker } from 'near-workspaces';
import { readFile } from 'fs/promises'
import test from 'ava';

function encodeCall(contract, method, args) {
return Buffer.concat([Buffer.from(contract), Buffer.from([0]), Buffer.from(method), Buffer.from([0]), Buffer.from(JSON.stringify(args))])
}

test.beforeEach(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
Expand Down
6 changes: 0 additions & 6 deletions tests/__tests__/function-params.ava.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Worker } from 'near-workspaces';
import { readFile } from 'fs/promises'
import test from 'ava';

function encodeCall(contract, method, args) {
return Buffer.concat([Buffer.from(contract), Buffer.from([0]), Buffer.from(method), Buffer.from([0]), Buffer.from(JSON.stringify(args))])
}

test.before(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
Expand All @@ -17,7 +12,6 @@ test.before(async t => {
const functionParamsContract = await root.devDeploy(
'build/function-params.wasm',
);
await functionParamsContract.call(functionParamsContract, 'init', {});

// Test users
const ali = await root.createSubAccount('ali');
Expand Down
6 changes: 0 additions & 6 deletions tests/__tests__/lookup-map.ava.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Worker } from 'near-workspaces';
import { readFile } from 'fs/promises'
import test from 'ava';

function encodeCall(contract, method, args) {
return Buffer.concat([Buffer.from(contract), Buffer.from([0]), Buffer.from(method), Buffer.from([0]), Buffer.from(JSON.stringify(args))])
}

test.beforeEach(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
Expand All @@ -17,7 +12,6 @@ test.beforeEach(async t => {
const lookupMapContract = await root.devDeploy(
'build/lookup-map.wasm',
);
await lookupMapContract.call(lookupMapContract, 'init', {});

// Test users
const ali = await root.createSubAccount('ali');
Expand Down
6 changes: 0 additions & 6 deletions tests/__tests__/lookup-set.ava.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Worker } from 'near-workspaces';
import { readFile } from 'fs/promises'
import test from 'ava';

function encodeCall(contract, method, args) {
return Buffer.concat([Buffer.from(contract), Buffer.from([0]), Buffer.from(method), Buffer.from([0]), Buffer.from(JSON.stringify(args))])
}

test.beforeEach(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
Expand All @@ -17,7 +12,6 @@ test.beforeEach(async t => {
const lookupSetContract = await root.devDeploy(
'build/lookup-set.wasm',
);
await lookupSetContract.call(lookupSetContract, 'init', {});
// Test users
const ali = await root.createSubAccount('ali');
const bob = await root.createSubAccount('bob');
Expand Down
1 change: 0 additions & 1 deletion tests/__tests__/test-public-key.ava.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Worker } from 'near-workspaces';
import test from 'ava';


test.before(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
Expand Down
1 change: 0 additions & 1 deletion tests/__tests__/test_math_api.ava.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Worker } from 'near-workspaces';
import test from 'ava';


test.before(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
Expand Down
1 change: 0 additions & 1 deletion tests/__tests__/test_storage_api.ava.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Worker } from 'near-workspaces';
import test from 'ava';


test.beforeEach(async t => {
// Use beforeEach instead of before to start from scratch state for each test
// Init the worker and start a Sandbox server
Expand Down
3 changes: 0 additions & 3 deletions tests/__tests__/typescript.ava.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Worker } from 'near-workspaces';
import test from 'ava';


test.before(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
Expand All @@ -13,8 +12,6 @@ test.before(async t => {
const typescriptContract = await root.devDeploy(
'build/typescript.wasm',
);
await typescriptContract.call(typescriptContract, 'init', {})

// Test users
const ali = await root.createSubAccount('ali');

Expand Down
6 changes: 0 additions & 6 deletions tests/__tests__/unordered-map.ava.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Worker } from 'near-workspaces';
import { readFile } from 'fs/promises'
import test from 'ava';

function encodeCall(contract, method, args) {
return Buffer.concat([Buffer.from(contract), Buffer.from([0]), Buffer.from(method), Buffer.from([0]), Buffer.from(JSON.stringify(args))])
}

test.beforeEach(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
Expand All @@ -17,7 +12,6 @@ test.beforeEach(async t => {
const unorderedMapContract = await root.devDeploy(
'build/unordered-map.wasm',
);
await unorderedMapContract.call(unorderedMapContract, 'init', {});
// Test users
const ali = await root.createSubAccount('ali');
const bob = await root.createSubAccount('bob');
Expand Down
6 changes: 0 additions & 6 deletions tests/__tests__/unordered-set.ava.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Worker } from 'near-workspaces';
import { readFile } from 'fs/promises'
import test from 'ava';

function encodeCall(contract, method, args) {
return Buffer.concat([Buffer.from(contract), Buffer.from([0]), Buffer.from(method), Buffer.from([0]), Buffer.from(JSON.stringify(args))])
}

test.beforeEach(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
Expand All @@ -17,7 +12,6 @@ test.beforeEach(async t => {
const unorderedSetContract = await root.devDeploy(
'build/unordered-set.wasm',
);
await unorderedSetContract.call(unorderedSetContract, 'init', {});

// Test users
const ali = await root.createSubAccount('ali');
Expand Down
2 changes: 0 additions & 2 deletions tests/__tests__/vector.ava.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Worker } from 'near-workspaces';
import { readFile } from 'fs/promises'
import test from 'ava';

test.beforeEach(async t => {
Expand All @@ -13,7 +12,6 @@ test.beforeEach(async t => {
const vectorContract = await root.devDeploy(
'build/vector.wasm',
);
await vectorContract.call(vectorContract, 'init', {});

// Test users
const ali = await root.createSubAccount('ali');
Expand Down
10 changes: 2 additions & 8 deletions tests/src/function-params.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
NearContract,
NearBindgen,
call,
view,
Expand All @@ -9,10 +8,9 @@ import {
/**
* Simple contract to test function parameters
*/
@NearBindgen
class FunctionParamsTestContract extends NearContract {
@NearBindgen({})
class FunctionParamsTestContract {
constructor() {
super()
this.val1 = 'default1';
this.val2 = 'default2';
this.val3 = 'default3';
Expand All @@ -30,8 +28,4 @@ class FunctionParamsTestContract extends NearContract {
get_values() {
return { val3: this.val3, val2: this.val2, val1: this.val1 }
}

default() {
return new FunctionParamsTestContract();
}
}
24 changes: 9 additions & 15 deletions tests/src/lookup-map.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
import {
NearContract,
NearBindgen,
call,
view,
LookupMap
} from 'near-sdk-js'
import {House, Room} from './model.js';
import { House, Room } from './model.js';

@NearBindgen
class LookupMapTestContract extends NearContract {
@NearBindgen({})
class LookupMapTestContract {
constructor() {
super()
this.lookupMap = new LookupMap('a');
}

default() {
return new LookupMapTestContract();
}

@view
get({key}) {
get({ key }) {
return this.lookupMap.get(key);
}

@view
containsKey({key}) {
containsKey({ key }) {
return this.lookupMap.containsKey(key);
}

@call
set({key, value}) {
set({ key, value }) {
this.lookupMap.set(key, value);
}

@call
remove_key({key}) {
remove_key({ key }) {
this.lookupMap.remove(key);
}

@call
extend({kvs}) {
extend({ kvs }) {
this.lookupMap.extend(kvs);
}

Expand All @@ -54,7 +48,7 @@ class LookupMapTestContract extends NearContract {
// restore class object from serialized data
const house = new House(houseObject.name, houseObject.rooms)
const roomObject = house.rooms[0]
const room = new Room(roomObject.name, roomObject.size)
const room = new Room(roomObject.name, roomObject.size)
return house.describe() + room.describe()
}
}
10 changes: 2 additions & 8 deletions tests/src/lookup-set.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import {
NearContract,
NearBindgen,
call,
view,
LookupSet
} from 'near-sdk-js'
import { House, Room } from './model.js';

@NearBindgen
class LookupSetTestContract extends NearContract {
@NearBindgen({})
class LookupSetTestContract {
constructor() {
super()
this.lookupSet = new LookupSet('a');
}

default() {
return new LookupSetTestContract();
}

@view
contains({ key }) {
return this.lookupSet.contains(key);
Expand Down
9 changes: 2 additions & 7 deletions tests/src/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import {
NearContract,
NearBindgen,
view,
} from 'near-sdk-js'

@NearBindgen
class TypeScriptTestContract extends NearContract {
@NearBindgen({})
class TypeScriptTestContract {
@view
bigint() {
// JSON.stringify cannot seriaize a BigInt, need manually toString
return (1n + 2n).toString()
}

default() {
return new TypeScriptTestContract()
}
}
21 changes: 7 additions & 14 deletions tests/src/unordered-map.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import {
NearContract,
NearBindgen,
call,
view,
UnorderedMap,
Vector
} from 'near-sdk-js'
import {House, Room} from './model.js';
import { House, Room } from './model.js';

@NearBindgen
class UnorderedMapTestContract extends NearContract {
@NearBindgen({})
class UnorderedMapTestContract {
constructor() {
super()
this.unorderedMap = new UnorderedMap('a');
}

default() {
return new UnorderedMapTestContract();
}

@view
len() {
return this.unorderedMap.length;
Expand All @@ -30,17 +23,17 @@ class UnorderedMapTestContract extends NearContract {
}

@view
get({key}) {
get({ key }) {
return this.unorderedMap.get(key);
}

@call
set({key, value}) {
set({ key, value }) {
this.unorderedMap.set(key, value);
}

@call
remove_key({key}) {
remove_key({ key }) {
this.unorderedMap.remove(key);
}

Expand All @@ -55,7 +48,7 @@ class UnorderedMapTestContract extends NearContract {
}

@call
extend({kvs}) {
extend({ kvs }) {
this.unorderedMap.extend(kvs);
}

Expand Down
Loading

0 comments on commit 714f783

Please sign in to comment.