-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProviderClient.test.ts
113 lines (91 loc) · 4.46 KB
/
ProviderClient.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { BOACoin, NetWorkType, ProviderClient } from "../src";
import * as assert from "assert";
import { BigNumber } from "@ethersproject/bignumber";
import { AddressZero } from "@ethersproject/constants";
describe("Test of ProviderClient", function () {
this.timeout(1000 * 60 * 5);
let providerClient: ProviderClient;
let agentClient: ProviderClient;
const network: NetWorkType = NetWorkType.testnet;
before(() => {
providerClient = new ProviderClient(
network,
"0x70438bc3ed02b5e4b76d496625cb7c06d6b7bf4362295b16fdfe91a046d4586c"
);
agentClient = new ProviderClient(network, "0x44868157d6d3524beb64c6ae41ee6c879d03c19a357dadb038fefea30e23cbab");
});
it("Check Provider", async () => {
const isProvider = await providerClient.isProvider(providerClient.address);
assert.ok(isProvider);
});
it("Test getBalanceAccount", async () => {
const res = await providerClient.getBalanceAccount(providerClient.address);
assert.ok(res.point.balance.gt(BigNumber.from(0)));
assert.ok(res.token.balance.gt(BigNumber.from(0)));
});
it("Test getBalancePhone", async () => {
const res = await providerClient.getBalancePhone("+82 10-1000-2000");
assert.ok(res.point.balance.gt(BigNumber.from(0)));
});
it("Clear agent", async () => {
await providerClient.setAgent(AddressZero);
assert.deepStrictEqual(await providerClient.getAgent(), AddressZero);
});
it("Provider to Address", async () => {
const isProvider = await providerClient.isProvider(providerClient.address);
const receiver = "0xB6f69F0e9e70034ba0578C542476cC13eF739269";
if (isProvider) {
const res1 = await providerClient.getBalanceAccount(receiver);
const oldBalance = res1.point.balance;
const amount = BOACoin.make(100).value;
await providerClient.provideToAddress(providerClient.address, receiver, amount);
const res2 = await providerClient.getBalanceAccount(receiver);
assert.deepStrictEqual(res2.point.balance, oldBalance.add(amount));
}
});
it("Provider to Phone", async () => {
const isProvider = await providerClient.isProvider(providerClient.address);
const phoneNumber = "+82 10-9000-5000";
if (isProvider) {
const res1 = await providerClient.getBalancePhone(phoneNumber);
const oldBalance = res1.point.balance;
const amount = BOACoin.make(100).value;
await providerClient.provideToPhone(providerClient.address, phoneNumber, amount);
const res2 = await providerClient.getBalancePhone(phoneNumber);
assert.deepStrictEqual(res2.point.balance, oldBalance.add(amount));
}
});
it("Set agent", async () => {
await providerClient.setAgent(agentClient.address);
assert.deepStrictEqual(await providerClient.getAgent(), agentClient.address);
});
it("Provider to Address by agent", async () => {
const isProvider = await providerClient.isProvider(providerClient.address);
const receiver = "0xB6f69F0e9e70034ba0578C542476cC13eF739269";
if (isProvider) {
const res1 = await providerClient.getBalanceAccount(receiver);
const oldBalance = res1.point.balance;
const amount = BOACoin.make(100).value;
await agentClient.provideToAddress(providerClient.address, receiver, amount);
const res2 = await providerClient.getBalanceAccount(receiver);
assert.deepStrictEqual(res2.point.balance, oldBalance.add(amount));
}
});
it("Provider to Phone by agent", async () => {
const isProvider = await providerClient.isProvider(providerClient.address);
const phoneNumber = "+82 10-9000-5000";
if (isProvider) {
const res1 = await providerClient.getBalancePhone(phoneNumber);
const oldBalance = res1.point.balance;
const amount = BOACoin.make(100).value;
await agentClient.provideToPhone(providerClient.address, phoneNumber, amount);
const res2 = await providerClient.getBalancePhone(phoneNumber);
assert.deepStrictEqual(res2.point.balance, oldBalance.add(amount));
}
});
it("Convert", async () => {
const amount = BOACoin.make(1).value;
const amount2 = await agentClient.convert(amount, "usd", "point");
console.log(amount2.toString());
});
});