Skip to content

Instantly share code, notes, and snippets.

@johngrantuk
Last active October 21, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngrantuk/85f4bc1d7c24fd9032ccb29ed18d4fde to your computer and use it in GitHub Desktop.
Save johngrantuk/85f4bc1d7c24fd9032ccb29ed18d4fde to your computer and use it in GitHub Desktop.
var LeaderToken = artifacts.require("LeaderToken");
var UniSwapFactory = artifacts.require("uniswap_factory");
var UniSwapExchange = artifacts.require("uniswap_exchange");
contract("UniSwapFactory", accounts => {
it("Add Liquidity.", async () => {
var UniSwapFactoryInstance = await UniSwapFactory.deployed();
var LeaderTokenInstance = await LeaderToken.deployed();
var ExchangeInstance = await UniSwapExchange.deployed();
var balance = await LeaderTokenInstance.balanceOf(accounts[0]);
console.log('Balance: ' + balance);
var templateAddress = await UniSwapFactoryInstance.exchangeTemplate();
assert.equal(templateAddress, '0x0000000000000000000000000000000000000000', "Factory should not be initialised.");
await UniSwapFactoryInstance.initializeFactory(ExchangeInstance.address)
var templateAddress = await UniSwapFactoryInstance.exchangeTemplate();
assert.notEqual(templateAddress, '0x0000000000000000000000000000000000000000', "Factory should be initialised.");
var exchangeAddress = await UniSwapFactoryInstance.getExchange(LeaderTokenInstance.address)
assert.equal(exchangeAddress, '0x0000000000000000000000000000000000000000', "Exchange should not be deployed.");
var txHash = await UniSwapFactoryInstance.createExchange(LeaderTokenInstance.address, { from: accounts[0] })
exchangeAddress = await UniSwapFactoryInstance.getExchange(LeaderTokenInstance.address)
assert.notEqual(exchangeAddress, '0x0000000000000000000000000000000000000000', "Exchange should be deployed.");
var approveQtyWei = web3.utils.toWei('100', 'ether');
var txHash = await LeaderTokenInstance.approve(exchangeAddress, approveQtyWei, { from: accounts[0] });
var allowance = await LeaderTokenInstance.allowance(accounts[0], exchangeAddress);
assert.equal(allowance.toString(), approveQtyWei, "Token Should Be Approved.");
var tokenBalance = await LeaderTokenInstance.balanceOf(accounts[0]);
assert.isTrue(tokenBalance > 0);
const MIN_LIQUIDITY = 0;
const ETH_ADDED = web3.utils.toWei('10', 'ether');
const TOKEN_ADDED = web3.utils.toWei('10', 'ether');
let contract = await UniSwapExchange.at(exchangeAddress);
//var name = await contract.tokenAddress();
//console.log(LeaderTokenInstance.address)
//console.log(name)
let block = await web3.eth.getBlock("latest");
const DEADLINE = block.timestamp + 300; // deadline = w3.eth.getBlock(w3.eth.blockNumber).timestamp
txHash = await contract.addLiquidity(MIN_LIQUIDITY, TOKEN_ADDED, DEADLINE,
{
from: accounts[0],
value: ETH_ADDED
}
)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment