This repository has been archived by the owner on Aug 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ts-tests): add e2e contracts (#66)
#### What this PR does / why we need it: Develop and test on a simple smart contract functionality on substrate-based blockchain. #### Which issue(s) does this PR fixes?: <!-- (Optional) Automatically closes linked issue when PR is merged. Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> Fixes # #### Additional comments?: Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f761111
commit 31bb3b8
Showing
13 changed files
with
3,476 additions
and
5,012 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ target | |
netlify.toml | ||
*.md | ||
Dockerfile | ||
ts-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,8 @@ build | |
node_modules | ||
.contented | ||
dist | ||
.turbo | ||
.turbo | ||
|
||
### Hardhat | ||
cache | ||
artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"singleQuote": true | ||
"printWidth": 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { MetaDContainer } from '../containers'; | ||
import { GENESIS_ACCOUNT, GENESIS_ACCOUNT_PRIVATE_KEY, CONTRACT_ADDRESS } from '../utils/constant'; | ||
import Test from '../artifacts/contracts/Test.sol/Test.json'; | ||
import { ethers } from 'ethers'; | ||
|
||
const container = new MetaDContainer(); | ||
|
||
beforeAll(async () => { | ||
await container.start(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await container.stop(); | ||
}); | ||
|
||
it('should create and call contract', async () => { | ||
// create contract | ||
const wallet = new ethers.Wallet(GENESIS_ACCOUNT_PRIVATE_KEY, container.ethers); | ||
|
||
const factory = new ethers.ContractFactory(Test.abi, Test.bytecode, wallet); | ||
|
||
const contract = await factory.deploy(); | ||
expect(contract.address).toStrictEqual(CONTRACT_ADDRESS); | ||
|
||
await container.generate(); | ||
|
||
// call contract | ||
expect(await contract.name()).toStrictEqual('Meta'); | ||
expect(await contract.owner()).toStrictEqual(GENESIS_ACCOUNT); | ||
|
||
// test environmental | ||
const currentBlock = (await contract.getCurrentBlock()).toNumber(); | ||
expect(currentBlock).toStrictEqual(1); | ||
|
||
const blockHash = await contract.getBlockHash(currentBlock); | ||
expect(blockHash).toStrictEqual(expect.any(String)); | ||
|
||
const gasLimit = (await contract.getGasLimit()).toNumber(); | ||
expect(gasLimit).toStrictEqual(75000000); | ||
|
||
// test functional | ||
const mul = (await contract.mul(3, 7)).toNumber(); | ||
expect(mul).toStrictEqual(21); | ||
|
||
const c0 = (await contract.getCount()).toNumber(); | ||
expect(c0).toStrictEqual(0); | ||
|
||
await contract.incr(); | ||
await container.generate(); | ||
|
||
const c1 = (await contract.getCount()).toNumber(); | ||
expect(c1).toStrictEqual(1); | ||
|
||
await contract.setCount(25); | ||
await container.generate(); | ||
|
||
const c25 = (await contract.getCount()).toNumber(); | ||
expect(c25).toStrictEqual(25); | ||
|
||
const promise = contract.max10(11); | ||
await expect(promise).rejects.toThrow('Value must not be greater than 10'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.