Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed May 27, 2024
1 parent a4a856e commit b393648
Show file tree
Hide file tree
Showing 21 changed files with 385 additions and 518 deletions.
2 changes: 1 addition & 1 deletion examples/notify_raw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"devDependencies": {
"@dfinity/agent": "0.11.1",
"ts-node": "10.7.0",
"typescript": "4.6.3"
"typescript": "5.2.2"
}
}
2 changes: 1 addition & 1 deletion examples/null_example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"devDependencies": {
"@dfinity/agent": "0.11.1",
"ts-node": "10.7.0",
"typescript": "4.6.3"
"typescript": "5.2.2"
}
}
2 changes: 1 addition & 1 deletion examples/optional_types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"@types/node-fetch": "2.6.1",
"node-fetch": "2.6.7",
"ts-node": "10.7.0",
"typescript": "4.6.3"
"typescript": "5.2.2"
}
}
2 changes: 1 addition & 1 deletion examples/outgoing_http_requests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@dfinity/agent": "0.11.1",
"decode-utf8": "1.0.1",
"ts-node": "10.7.0",
"typescript": "4.6.3",
"typescript": "5.2.2",
"utf8-encoder": "1.0.1"
}
}
2 changes: 1 addition & 1 deletion examples/randomness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"devDependencies": {
"@dfinity/agent": "0.11.1",
"ts-node": "10.7.0",
"typescript": "4.6.3"
"typescript": "5.2.2"
}
}
2 changes: 1 addition & 1 deletion examples/rejections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"devDependencies": {
"@dfinity/agent": "0.11.1",
"ts-node": "10.7.0",
"typescript": "4.6.3"
"typescript": "5.2.2"
}
}
2 changes: 1 addition & 1 deletion examples/robust_imports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"devDependencies": {
"@dfinity/agent": "0.18.1",
"ts-node": "10.7.0",
"typescript": "4.6.3"
"typescript": "5.2.2"
}
}
4 changes: 1 addition & 3 deletions examples/run_time_errors/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export function expectError(
return {
name,
test: async () => {
return {
Ok: await testThrow(canisterMethod, expectedValue)
};
return test(await testThrow(canisterMethod, expectedValue));
}
};
}
Expand Down
50 changes: 13 additions & 37 deletions examples/simple_erc20/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActorSubclass } from '@dfinity/agent';
import { Test } from 'azle/test';
import { Test, test, testEquality } from 'azle/test';

import { _SERVICE } from './dfx_generated/simple_erc20/simple_erc20.did';

Expand All @@ -10,39 +10,31 @@ export function getTests(simpleErc20Canister: ActorSubclass<_SERVICE>): Test[] {
test: async () => {
const result = await simpleErc20Canister.name();

return {
Ok: result === ''
};
return testEquality(result, '');
}
},
{
name: 'empty ticker',
test: async () => {
const result = await simpleErc20Canister.ticker();

return {
Ok: result === ''
};
return testEquality(result, '');
}
},
{
name: 'empty totalSupply',
test: async () => {
const result = await simpleErc20Canister.totalSupply();

return {
Ok: result === 0n
};
return testEquality(result, 0n);
}
},
{
name: 'empty balance of id 0',
test: async () => {
const result = await simpleErc20Canister.balance('0');

return {
Ok: result === 0n
};
return testEquality(result, 0n);
}
},
{
Expand All @@ -55,49 +47,39 @@ export function getTests(simpleErc20Canister: ActorSubclass<_SERVICE>): Test[] {
1_000_000n
);

return {
Ok: result === true
};
return testEquality(result, true);
}
},
{
name: 'initialized name',
test: async () => {
const result = await simpleErc20Canister.name();

return {
Ok: result === 'Token'
};
return testEquality(result, 'Token');
}
},
{
name: 'initialized ticker',
test: async () => {
const result = await simpleErc20Canister.ticker();

return {
Ok: result === 'TOKEN'
};
return testEquality(result, 'TOKEN');
}
},
{
name: 'initialized totalSupply',
test: async () => {
const result = await simpleErc20Canister.totalSupply();

return {
Ok: result === 1_000_000n
};
return testEquality(result, 1_000_000n);
}
},
{
name: 'initialized balance of id 0',
test: async () => {
const result = await simpleErc20Canister.balance('0');

return {
Ok: result === 1_000_000n
};
return testEquality(result, 1_000_000n);
}
},
{
Expand All @@ -109,29 +91,23 @@ export function getTests(simpleErc20Canister: ActorSubclass<_SERVICE>): Test[] {
100n
);

return {
Ok: result === true
};
return test(result);
}
},
{
name: 'balance of id 0 after transfer',
test: async () => {
const result = await simpleErc20Canister.balance('0');

return {
Ok: result === 999_900n
};
return testEquality(result, 999_990n);
}
},
{
name: 'balance of id 1 after transfer',
test: async () => {
const result = await simpleErc20Canister.balance('1');

return {
Ok: result === 100n
};
return testEquality(result, 100n);
}
}
];
Expand Down
32 changes: 10 additions & 22 deletions examples/simple_user_accounts/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActorSubclass } from '@dfinity/agent';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

import { _SERVICE } from './dfx_generated/simple_user_accounts/simple_user_accounts.did';

Expand All @@ -13,57 +13,45 @@ export function getTests(
const result =
await simpleUserAccountsCanister.getUserById('0');

return {
Ok: result.length === 0
};
return testEquality(result.length, 0);
}
},
{
name: 'getAllUsers',
test: async () => {
const result = await simpleUserAccountsCanister.getAllUsers();

return {
Ok: result.length === 0
};
return testEquality(result.length, 0);
}
},
{
name: 'createUser',
test: async () => {
const result =
await simpleUserAccountsCanister.createUser('lastmjs');
const expected = { id: '0', username: 'lastmjs' };

return {
Ok: result.id === '0' && result.username === 'lastmjs'
};
return testEquality(result, expected);
}
},
{
name: 'getUserById',
test: async () => {
const result =
await simpleUserAccountsCanister.getUserById('0');
const expected = { id: '0', username: 'lastmjs' };

return {
Ok:
result.length !== 0 &&
result[0].id === '0' &&
result[0].username === 'lastmjs'
};
return testEquality(result, [expected]);
}
},
{
name: 'getAllUsers',
test: async () => {
const result = await simpleUserAccountsCanister.getAllUsers();

return {
Ok:
result.length === 1 &&
result[0].id === '0' &&
result[0].username === 'lastmjs'
};
const expected = { id: '0', username: 'lastmjs' };

return testEquality(result, [expected]);
}
}
];
Expand Down
12 changes: 4 additions & 8 deletions examples/sqlite/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as dns from 'node:dns';
dns.setDefaultResultOrder('ipv4first');

import { Test } from 'azle/test';
import { error, Test, testEquality } from 'azle/test';

export function getTests(canisterId: string): Test[] {
const origin = `http://${canisterId}.localhost:8000`;
Expand All @@ -16,13 +16,9 @@ export function getTests(canisterId: string): Test[] {
});
const responseText = await response.text();

return {
Ok: responseText === 'Hello world'
};
} catch (error: any) {
return {
Err: error
};
return testEquality(responseText, 'Hello world');
} catch (err: any) {
return error(err);
}
}
}
Expand Down
44 changes: 25 additions & 19 deletions examples/stable_b_tree_map_instruction_threshold/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActorSubclass } from '@dfinity/agent';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

import { _SERVICE } from './dfx_generated/stable_b_tree_map_instruction_threshold/stable_b_tree_map_instruction_threshold.did';

Expand Down Expand Up @@ -29,12 +29,14 @@ export function getTests(
1_000
);

return {
Ok:
keysResult.length === 4_000 &&
valuesResult.length === 5_000 &&
itemsResult.length === 1_000
};
return testEquality(
[
keysResult.length,
valuesResult.length,
itemsResult.length
],
[4_000, 5_000, 1_000]
);
}
},
{
Expand All @@ -59,12 +61,14 @@ export function getTests(
1_000
);

return {
Ok:
keysResult.length === 1_000 &&
valuesResult.length === 1_000 &&
itemsResult.length === 1_000
};
return testEquality(
[
keysResult.length,
valuesResult.length,
itemsResult.length
],
[1_000, 1_000, 1_000]
);
}
},
{
Expand All @@ -89,12 +93,14 @@ export function getTests(
400
);

return {
Ok:
keysResult.length === 500 &&
valuesResult.length === 500 &&
itemsResult.length === 400
};
return testEquality(
[
keysResult.length,
valuesResult.length,
itemsResult.length
],
[500, 500, 400]
);
}
}
];
Expand Down
Loading

0 comments on commit b393648

Please sign in to comment.