-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsablier.spec.ts
119 lines (93 loc) · 4.37 KB
/
sablier.spec.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
114
115
116
117
118
119
import {
defaultWeb3Connection,
erc20Deployer, getChainDate,
getPrivateKeyFromFile,
hasTxBlockNumber, increaseTime,
modelExtensionDeployer,
} from '../utils';
import {Account} from 'web3-core';
import {CERC20, ERC20, ETHUtils, Sablier, Web3Connection} from '../../src';
import {
AMOUNT_1M,
INITIAL_EXCHANGE_RATE,
SALARY,
STANDARD_SABLIER_FEE, START_TIME_DELTA, START_TIME_OFFSET,
} from '../utils/constants';
import {toSmartContractDate, toSmartContractDecimals} from '../../src';
import {addSeconds} from 'date-fns'
import {expect} from 'chai';
describe.skip(`Sablier`, () => {
let web3Connection: Web3Connection;
let Alice: Account;
let Bob: Account;
let Admin: Account;
let ethUtils: ETHUtils;
let erc20: ERC20;
let cerc20: CERC20;
let sablier: Sablier;
let contractAddress: string;
let erc20ContractAddress: string;
before(async () => {
web3Connection = await defaultWeb3Connection(true, true);
Alice = await web3Connection.Web3.eth.accounts.privateKeyToAccount(getPrivateKeyFromFile(1));
Bob = await web3Connection.Web3.eth.accounts.privateKeyToAccount(getPrivateKeyFromFile(2));
Admin = await web3Connection.Web3.eth.accounts.privateKeyToAccount(getPrivateKeyFromFile());
const ethUtilsTx = await modelExtensionDeployer(web3Connection, ETHUtils);
ethUtils = new ETHUtils(web3Connection, ethUtilsTx.contractAddress);
await ethUtils.start();
const erc20Tx = await erc20Deployer(`My Sablier`, `$sablier`, toSmartContractDecimals(AMOUNT_1M), web3Connection);
erc20 = new ERC20(web3Connection, erc20Tx.contractAddress);
await erc20.start();
const cercTx = await modelExtensionDeployer(web3Connection, CERC20, [erc20.contractAddress, INITIAL_EXCHANGE_RATE, 18]);
cerc20 = new CERC20(web3Connection, cercTx.contractAddress, erc20.contractAddress!);
await cerc20.start();
await web3Connection.switchToAccount(Admin.privateKey); // go back to the original account that created contracts
await erc20.transferTokenAmount(Alice.address, SALARY);
await erc20.transferTokenAmount(Bob.address, SALARY);
await erc20.approve(cerc20.contractAddress!, AMOUNT_1M);
await cerc20.supplyUnderlying(SALARY);
erc20ContractAddress = erc20.contractAddress!;
});
it(`Should deploy sablier`, async () => {
const tx = await modelExtensionDeployer(web3Connection, Sablier);
expect(tx.contractAddress).to.not.be.empty;
contractAddress = tx.contractAddress!;
});
describe(`With sablier contract`, () => {
let startTime = new Date(0);
let streamId = 0;
before(async () => {
sablier = new Sablier(web3Connection, contractAddress);
await sablier.start();
startTime = await getChainDate(web3Connection);
});
it(`Updates fee`, async () => {
await hasTxBlockNumber(sablier.updateFee(+STANDARD_SABLIER_FEE));
expect(await sablier.fee()).to.eq((+STANDARD_SABLIER_FEE/100).toString());
});
it(`Creates a compounding stream`, async () => {
await hasTxBlockNumber(erc20.approve(contractAddress, AMOUNT_1M), `Admin should have approved Sablier contract`);
startTime = addSeconds(startTime, START_TIME_OFFSET);
const endTime = addSeconds(startTime, START_TIME_DELTA);
const stream = await sablier.createStream(Bob.address,
SALARY,
erc20ContractAddress,
toSmartContractDate(Math.round(+startTime)),
toSmartContractDate(Math.round(+endTime)));
const events = await sablier.contract.self.getPastEvents(`CreateStream`, {fromBlock: stream.blockNumber});
expect(events[0].returnValues['streamId']).to.not.be.empty;
streamId = events[0].returnValues['streamId'];
});
it(`Gets stream`, async () => {
const stream = await sablier.getStream(streamId);
expect(stream.tokenAddress).to.be.eq(erc20ContractAddress);
});
it(`Withdraw from stream`, async () => {
await increaseTime(START_TIME_OFFSET + START_TIME_DELTA + 5, web3Connection.Web3);
const balance = await erc20.getTokenAmount(Bob.address);
await hasTxBlockNumber(sablier.withdrawFromStream(streamId, SALARY / 2));
const newBalance = await erc20.getTokenAmount(Bob.address);
expect(newBalance).to.be.eq((+balance + (SALARY / 2)).toString());
});
})
})