Skip to content

Commit

Permalink
Merge pull request #1872 from demergent-labs/jest_s
Browse files Browse the repository at this point in the history
jest examples s
  • Loading branch information
lastmjs authored Jul 9, 2024
2 parents 84bab34 + 9856cbf commit 8067371
Show file tree
Hide file tree
Showing 38 changed files with 72,335 additions and 17,548 deletions.
10 changes: 10 additions & 0 deletions examples/simple_erc20/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.js$': 'ts-jest'
},
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed
};
9,403 changes: 7,689 additions & 1,714 deletions examples/simple_erc20/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion examples/simple_erc20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"name": "simple_erc20_end_to_end_test_canister_syntax",
"scripts": {
"pretest": "ts-node --transpile-only --ignore=false test/pretest.ts",
"test": "ts-node --transpile-only --ignore=false test/test.ts"
"test": "jest"
},
"dependencies": {
"azle": "0.22.0"
},
"devDependencies": {
"@dfinity/agent": "0.11.1",
"jest": "^29.7.0",
"ts-jest": "^29.1.5",
"ts-node": "10.7.0",
"typescript": "^5.2.2"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_erc20/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getCanisterId } from 'azle/dfx';
import { runTests } from 'azle/test';

import { createActor } from '../test/dfx_generated/simple_erc20';
import { createActor } from './dfx_generated/simple_erc20';
import { getTests } from './tests';

const simpleErc20Canister = createActor(getCanisterId('simple_erc20'), {
Expand Down
213 changes: 80 additions & 133 deletions examples/simple_erc20/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,139 +1,86 @@
import { ActorSubclass } from '@dfinity/agent';
import { Test } from 'azle/test';
import { expect, it, Test } from 'azle/test';

// @ts-ignore this path may not exist when these tests are imported into other test projects
import { _SERVICE } from './dfx_generated/simple_erc20/simple_erc20.did';

export function getTests(simpleErc20Canister: ActorSubclass<_SERVICE>): Test[] {
return [
{
name: 'empty name',
test: async () => {
const result = await simpleErc20Canister.name();

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

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

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

return {
Ok: result === 0n
};
}
},
{
name: 'initializeSupply',
test: async () => {
const result = await simpleErc20Canister.initializeSupply(
'Token',
'0',
'TOKEN',
1_000_000n
);

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

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

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

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

return {
Ok: result === 1_000_000n
};
}
},
{
name: 'transfer',
test: async () => {
const result = await simpleErc20Canister.transfer(
'0',
'1',
100n
);

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

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

return {
Ok: result === 100n
};
}
}
];
export function getTests(simpleErc20Canister: ActorSubclass<_SERVICE>): Test {
return () => {
it('empty name', async () => {
const result = await simpleErc20Canister.name();

expect(result).toBe('');
});

it('empty ticker', async () => {
const result = await simpleErc20Canister.ticker();

expect(result).toBe('');
});

it('empty totalSupply', async () => {
const result = await simpleErc20Canister.totalSupply();

expect(result).toBe(0n);
});

it('empty balance of id 0', async () => {
const result = await simpleErc20Canister.balance('0');

expect(result).toBe(0n);
});

it('initializeSupply', async () => {
const result = await simpleErc20Canister.initializeSupply(
'Token',
'0',
'TOKEN',
1_000_000n
);

expect(result).toBe(true);
});

it('initialized name', async () => {
const result = await simpleErc20Canister.name();

expect(result).toBe('Token');
});

it('initialized ticker', async () => {
const result = await simpleErc20Canister.ticker();

expect(result).toBe('TOKEN');
});

it('initialized totalSupply', async () => {
const result = await simpleErc20Canister.totalSupply();

expect(result).toBe(1_000_000n);
});

it('initialized balance of id 0', async () => {
const result = await simpleErc20Canister.balance('0');

expect(result).toBe(1_000_000n);
});

it('transfer', async () => {
const result = await simpleErc20Canister.transfer('0', '1', 100n);

expect(result).toBe(true);
});

it('balance of id 0 after transfer', async () => {
const result = await simpleErc20Canister.balance('0');

expect(result).toBe(999_900n);
});

it('balance of id 1 after transfer', async () => {
const result = await simpleErc20Canister.balance('1');

expect(result).toBe(100n);
});
};
}
10 changes: 10 additions & 0 deletions examples/simple_user_accounts/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.js$': 'ts-jest'
},
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed
};
Loading

0 comments on commit 8067371

Please sign in to comment.