Skip to content

Commit 05f5a7a

Browse files
authored
Merge pull request #2 from pontem-network/feat/tests
feat: add unit testing for coins and coins extended
2 parents a93ba01 + 2905412 commit 05f5a7a

File tree

5 files changed

+143
-2
lines changed

5 files changed

+143
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Tests
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
tests:
10+
name: Test
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v2
19+
20+
- name: Get Aptos
21+
uses: pontem-network/get-aptos@main
22+
with:
23+
version: latest
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Build
27+
run: aptos move compile
28+
29+
- name: Test
30+
run: aptos move test

Move.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ subdir = 'aptos-move/framework/aptos-framework'
99

1010
[addresses]
1111
test_coins = "0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9"
12-
test_coins_extended = "0xb4d7b2466d211c1f4629e8340bb1a9e75e7f8fb38cc145c54c5c9f9d5017a318"
12+
test_coins_extended = "0xb4d7b2466d211c1f4629e8340bb1a9e75e7f8fb38cc145c54c5c9f9d5017a318"
13+
14+
test_token_admin = "0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9"
15+
test_token_extended_admin = "0xb4d7b2466d211c1f4629e8340bb1a9e75e7f8fb38cc145c54c5c9f9d5017a318"
16+
test_account = "0x15"

sources/coins_extended.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module test_coins_extended::coins_extended {
1919
burn: BurnCapability<CoinType>,
2020
}
2121

22-
/// Initializes `BTC` and `USDT` coins.
22+
/// Initializes `ETH`, `USDC`, and `DAI` coins.
2323
public entry fun register_coins(token_admin: &signer) {
2424
let (eth_b, eth_f, eth_m) =
2525
coin::initialize<ETH>(token_admin,

tests/coins_extended_tests.move

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#[test_only]
2+
module test_coins::coins_extended_tests {
3+
use std::signer;
4+
use std::string::utf8;
5+
6+
use aptos_framework::coin;
7+
use test_coins_extended::coins_extended::{ETH, DAI, USDC, register_coins, mint_coin};
8+
use aptos_framework::genesis;
9+
use aptos_framework::aptos_account::create_account;
10+
11+
12+
#[test(token_admin = @test_token_extended_admin)]
13+
fun test_register_coins(token_admin: signer) {
14+
genesis::setup();
15+
create_account(signer::address_of(&token_admin));
16+
17+
register_coins(&token_admin);
18+
19+
assert!(coin::is_coin_initialized<ETH>(), 0);
20+
assert!(coin::is_coin_initialized<USDC>(), 1);
21+
assert!(coin::is_coin_initialized<DAI>(), 2);
22+
23+
assert!(coin::name<ETH>() == utf8(b"ETH"), 3);
24+
assert!(coin::symbol<ETH>() == utf8(b"ETH"), 4);
25+
assert!(coin::decimals<ETH>() == 8, 5);
26+
27+
assert!(coin::name<USDC>() == utf8(b"USDC"), 6);
28+
assert!(coin::symbol<USDC>() == utf8(b"USDC"), 7);
29+
assert!(coin::decimals<USDC>() == 6, 8);
30+
31+
assert!(coin::name<DAI>() == utf8(b"DAI"), 9);
32+
assert!(coin::symbol<DAI>() == utf8(b"DAI"), 10);
33+
assert!(coin::decimals<DAI>() == 6, 11);
34+
}
35+
36+
#[test(token_admin = @test_token_extended_admin, test_account = @test_account)]
37+
fun test_mint_coin(token_admin: signer, test_account: signer) {
38+
let account_address = signer::address_of(&test_account);
39+
40+
genesis::setup();
41+
create_account(signer::address_of(&token_admin));
42+
create_account(account_address);
43+
44+
register_coins(&token_admin);
45+
46+
coin::register<ETH>(&test_account);
47+
mint_coin<ETH>(&token_admin, account_address, 100000000);
48+
assert!(coin::balance<ETH>(account_address) == 100000000, 0);
49+
50+
coin::register<USDC>(&test_account);
51+
mint_coin<USDC>(&token_admin, account_address, 1000000);
52+
assert!(coin::balance<USDC>(account_address) == 1000000, 1);
53+
54+
coin::register<DAI>(&test_account);
55+
mint_coin<DAI>(&token_admin, account_address, 1000000);
56+
assert!(coin::balance<DAI>(account_address) == 1000000, 1);
57+
}
58+
}

tests/coins_tests.move

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#[test_only]
2+
module test_coins::coins_tests {
3+
use std::signer;
4+
use std::string::utf8;
5+
6+
use aptos_framework::coin;
7+
use test_coins::coins::{BTC, USDT, register_coins, mint_coin};
8+
use aptos_framework::genesis;
9+
use aptos_framework::aptos_account::create_account;
10+
11+
12+
#[test(token_admin = @test_token_admin)]
13+
fun test_register_coins(token_admin: signer) {
14+
genesis::setup();
15+
create_account(signer::address_of(&token_admin));
16+
17+
register_coins(&token_admin);
18+
19+
assert!(coin::is_coin_initialized<BTC>(), 0);
20+
assert!(coin::is_coin_initialized<USDT>(), 1);
21+
22+
assert!(coin::name<BTC>() == utf8(b"Bitcoin"), 2);
23+
assert!(coin::symbol<BTC>() == utf8(b"BTC"), 3);
24+
assert!(coin::decimals<BTC>() == 8, 4);
25+
26+
assert!(coin::name<USDT>() == utf8(b"Tether"), 5);
27+
assert!(coin::symbol<USDT>() == utf8(b"USDT"), 6);
28+
assert!(coin::decimals<USDT>() == 6, 7);
29+
}
30+
31+
#[test(token_admin = @test_token_admin, test_account = @test_account)]
32+
fun test_mint_coin(token_admin: signer, test_account: signer) {
33+
let account_address = signer::address_of(&test_account);
34+
35+
genesis::setup();
36+
create_account(signer::address_of(&token_admin));
37+
create_account(account_address);
38+
39+
register_coins(&token_admin);
40+
41+
coin::register<BTC>(&test_account);
42+
mint_coin<BTC>(&token_admin, account_address, 100000000);
43+
assert!(coin::balance<BTC>(account_address) == 100000000, 0);
44+
45+
coin::register<USDT>(&test_account);
46+
mint_coin<USDT>(&token_admin, account_address, 1000000);
47+
assert!(coin::balance<USDT>(account_address) == 1000000, 1);
48+
}
49+
}

0 commit comments

Comments
 (0)