forked from stakewithus/defi-by-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-curve-exchange.js
48 lines (39 loc) · 1.32 KB
/
test-curve-exchange.js
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
const BN = require("bn.js")
const { sendEther, pow } = require("./util")
const { DAI, DAI_WHALE, USDC, USDC_WHALE, USDT, USDT_WHALE } = require("./config")
const IERC20 = artifacts.require("IERC20")
const TestCurveExchange = artifacts.require("TestCurveExchange")
contract("TestCurveExchange", (accounts) => {
const WHALE = USDC_WHALE
const TOKEN_IN = USDC
const TOKEN_IN_INDEX = 1
const TOKEN_OUT = USDT
const TOKEN_OUT_INDEX = 2
const DECIMALS = 6
const TOKEN_IN_AMOUNT = pow(10, DECIMALS).mul(new BN(1000000))
let testContract
let tokenIn
let tokenOut
beforeEach(async () => {
tokenIn = await IERC20.at(TOKEN_IN)
tokenOut = await IERC20.at(TOKEN_OUT)
testContract = await TestCurveExchange.new()
await sendEther(web3, accounts[0], WHALE, 1)
const bal = await tokenIn.balanceOf(WHALE)
assert(bal.gte(TOKEN_IN_AMOUNT), "balance < TOKEN_IN_AMOUNT")
await tokenIn.transfer(testContract.address, TOKEN_IN_AMOUNT, {
from: WHALE,
})
})
it("exchange", async () => {
const snapshot = async () => {
return {
tokenOut: await tokenOut.balanceOf(testContract.address),
}
}
// const before = await snapshot()
await testContract.swap(TOKEN_IN_INDEX, TOKEN_OUT_INDEX)
const after = await snapshot()
console.log(`Token out: ${after.tokenOut}`)
})
})