Was not sure how to call Eth balance, so i just used the word “Ethbalance” at :The SELL market order should sell for the highest price available in the orderbook.
How should i have called for the Eth balance?
Also was not sure if we could use decimals.I believe not but then how to write:
price = 0.02
Here is my version:
// The user must have ETH deposited such that deposited eth >= buy order value
// The user must have enough tokens deposited such that token balance >= sell order amount
// The BUY orderbook should be ordered on price from highest to lowest starting at index [0]
// The SELL orderbook should be ordered on price from lowest to highest starting at index [0]
// The BUY market order should get the lowest price available in the orderbook.
// The SELL market order should sell for the highest price available in the orderbook.
// Price should be last order match
const Dex = artifacts.require("Dex")
const link = artifacts.require("Link")
const truffleAssert = require('truffle-assertions');
contract("Dex", accounts => {
it("should have enough ETH deposited such that deposited eth >= buy order value", async () => {
let dex = await Dex.deployed();
let Link = await link.deployed();
await dex.depositETH({value: 3});
await truffleAssert.reverts(dex.BuyLimitOrder(100, 4, web3.utils.fromUtf8("link")));
await truffleAssert.passes(dex.BuyLimitOrder(100, 3, web3.utils.fromUtf8("link")));
})
it("should have enough tokens deposited such that token balance >= sell order amount", async () => {
let dex = await Dex.deployed();
let Link = await link.deployed();
await Link.approve(dex.address, 500);
await dex.deposit(100, web3.utils.fromUtf8("link"));
let Linkbalance = await dex.balances(accounts[0], web3.utils.fromUtf8("link"));
await truffleAssert.reverts(dex.SellLimitOrder(200, , web3.utils.fromUtf8("link")));
await truffleAssert.passes(dex.SellLimitOrder(100, web3.utils.fromUtf8("link")));
})
it("The BUY orderbook should be ordered on price from highest to lowest starting at index [0]", async () => {
let dex = await Dex.deployed();
let Link = await link.deployed();
let index0 = await dex.orderBook(web3.utils.fromUtf8("link"), 1,[0])
let index1 = await dex.orderBook(web3.utils.fromUtf8("link"), 1,[1])
let index2 = await dex.orderBook(web3.utils.fromUtf8("link"), 1,[2])
assert.true(index0 > index1);
assert.true(index1 > index2);
assert.true(index2 > index3);
})
it("The SELL orderbook should be ordered on price from lowest to highest starting at index [0]", async () => {
let dex = await Dex.deployed();
let Link = await link.deployed();
let index0 = await dex.orderBook(web3.utils.fromUtf8("link"), 0,[0])
let index1 = await dex.orderBook(web3.utils.fromUtf8("link"), 0,[1])
let index2 = await dex.orderBook(web3.utils.fromUtf8("link"), 0,[2])
assert.true(index0 < index1);
assert.true(index1 < index2);
assert.true(index2 < index3);
})
})
it("The BUY market order should get the lowest price available in the orderbook.", async () => {
let dex = await Dex.deployed();
let Link = await link.deployed();
await Link.approve(dex.address, 500);
await dex.deposit(300, web3.utils.fromUtf8("link"));
await dex.SellLimitOrder(100, 1,web3.utils.fromUtf8("link"));
await dex.SellLimitOrder(100, 2,web3.utils.fromUtf8("link"));
await dex.SellLimitOrder(100, 3,web3.utils.fromUtf8("link"));
await dex.depositETH({value: 3});
await dex.BuyMarketOrder(1, web3.utils.fromUtf8("link"));
let balance = await dex.balances(accounts[0], web3.utils.fromUtf8("link"));
assert.equal(balance.toNumber(), 100);
})
it("The SELL market order should sell for the highest price available in the orderbook.", async () => {
let dex = await Dex.deployed();
let Link = await link.deployed();
await dex.depositETH({value: 6});
await dex.BuyLimitOrder(100, 3,web3.utils.fromUtf8("link"));
await dex.BuyLimitOrder(100, 2,web3.utils.fromUtf8("link"));
await dex.BuyLimitOrder(100, 1,web3.utils.fromUtf8("link"));
await Link.approve(dex.address, 500);
await dex.deposit(300, web3.utils.fromUtf8("link"));
await dex.SellMarketOrder(100, web3.utils.fromUtf8("link"));
let balance = await dex.balances(accounts[0], web3.utils.fromUtf8("link"));
assert.equal(Ethbalance.toNumber(), 3);
})
it("// Price should be last order match", async () => {
let dex = await Dex.deployed();
let Link = await link.deployed();
await dex.depositETH({value: 6});
await dex.BuyLimitOrder(100, 3,web3.utils.fromUtf8("link"));
await dex.BuyLimitOrder(100, 2,web3.utils.fromUtf8("link"));
await dex.BuyLimitOrder(100, 1,web3.utils.fromUtf8("link"));
await Link.approve(dex.address, 500);
await dex.deposit(300, web3.utils.fromUtf8("link"));
await dex.SellLimitOrder(100, 1,web3.utils.fromUtf8("link"));
await dex.SellLimitOrder(100, 2,web3.utils.fromUtf8("link"));
assert.equal(Price.toNumber(), 0.02);
})
})