Skip to content

Commit

Permalink
solving issues of test
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandGarcon committed Jun 27, 2022
1 parent 7f76fc3 commit 979262d
Showing 1 changed file with 44 additions and 60 deletions.
104 changes: 44 additions & 60 deletions test/DGOV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,123 +2,107 @@ import {expect} from "chai";
import Web3 from "web3";
import {DGOVInstance, DBITAirdropInstance} from "../types/truffle-contracts";

const DBIT = artifacts.require("DGOV");
const DBITAirdrop = artifacts.require("DBITAirdrop");
const DGOV = artifacts.require("DGOV");
const web3 = require('web3');
contract("DBIT token", async (accounts: any) => {
let dgovObj: DBITInstance;
contract("DGOV token", async (accounts: any) => {
let dgovObj: DGOVInstance;
// TODO: just taken as the demo for replicating the ng the other contracts , to be removed
let Bank: BankInstance;
let Governance: GovernanceInstance
let DBITAirdrop: DBITAirdropInstance;
let Exchange: ExchangeInstance;

let [deployer, User1, User2, bank, exchange] = accounts;
let [governance, bankAddress, airdropAddress, exchangeAddress, User1, User2]= accounts;


before('instantiation', async () => {


dgovObj = await DGOV.deployed();
// TODO: to change name for the DBITAirdrop to general airdrop.
DBITAirdrop = await DBITAirdrop.deployed();
Governance = await governance.deployed();
Exchange = await exchange.deployed();
Bank = await bank.deployed();
await dgovObj.setBankContract(bank, {from: deployer});
await dgovObj.setExchangeContract(exchange, {from: deployer});
dgovObj.setAirdropAddress(airdropAddress,{from:governance});
dgovObj.setBankAddress(bankAddress, {from:governance});
dgovObj.setExchangeAddress(exchangeAddress,{from:governance});

console.log("Airdrop address",await dgovObj.airdropAddress());
console.log(" Bank Address", await dgovObj.bankAddress());
console.log("exchange Address", await dgovObj.exchangeAddress());
console.log("governance Address",governance);

});


it('DBIT token is deployed', async () => {
it('DGOV token is deployed', async () => {
console.log(dgovObj.address);
expect(dgovObj.address).not.to.equal("");


});

it('DBIT is able to set contract address', async () => {
expect(await dgovObj.setAirdropContract(DBITAirdrop.address)).not.to.equal(false);
expect(await dgovObj.setExchangeContract(Exchange.address)).not.to.equal(false);
expect(await dgovObj.setBankContract(Bank.address)).not.to.equal(false);
})


it('is able to mint the collateralised supply only bankAddress', async () => {

it('is able to mint the collateralised supply via bank', async () => {

await dgovObj.mintCollateralisedSupply(User2, 100, {from: Bank.address});
expect(web3.eth.Balance(User2)).to.be('100');
await dgovObj.mintCollateralisedSupply(User2, web3.utils.toNumber(100), {from: bankAddress});
expect(dgovObj.getCollateralisedBalance(User2)).to.be(web3.utils.toNumber(100));
});


it('able to mint the allocated supply', async () => {

await dgovObj.mintAllocatedSupply(User2, 100, {from: Governance.address});
expect(web3.eth.Balance(User2)).to.be('100');
await dgovObj.mintAllocatedSupply(User2, 100, {from: governance});
expect(dgovObj.getAllocatedBalance(User2)).to.be(web3.utils.toNumber(100));

});


it('able to mint the airdroped supply', async () => {

await dgovObj.mintAirdroppedSupply(User2, '100', {from: DBITAirdrop.address});
expect(dgovObj.LockedBalance(User2, {from: User2})).to.be('100');
await dgovObj.mintAirdropSupply(User2, '100', {from: airdropAddress});
expect(dgovObj.getAirdropBalance(User2, {from: User2})).to.be(Web3.utils.toWei('100', 'ether'));

});

it('total supply is sum of the airdrop + collateral + allocated supply ', async () => {
await dgovObj.mintAirdroppedSupply(User2, '100', {from: DBITAirdrop.address});
await dgovObj.mintAirdropSupply(User2, '100', {from: airdropAddress});
await dgovObj.mintCollateralisedSupply(User2, '200', {from: User2});
await dgovObj.mintAllocatedSupply(User2, 300, {from: User2});
expect(dgovObj.totalSupply({from: User2})).to.equal('600');
await dgovObj.mintAllocatedSupply(User2, '300', {from: User2});
expect(dgovObj.totalSupply({from: User2})).to.equal(web3.utils.toWei('600', 'ether'));
});


it('gets the locked supply initially as full supply ', async () => {
// setting only the airdropped supply for the 2 users and no collateralised supply
await dgovObj.setAirdroppedSupply('200', {from: deployer});
await dgovObj.mintAirdroppedSupply(User2, '100', {from: DBITAirdrop.address});
await dgovObj.mintAirdroppedSupply(User1, '100', {from: DBITAirdrop.address});
await dgovObj.setMaxAirdropSupply('200', {from: governance});
await dgovObj.mintAirdropSupply(User2, '100', {from: airdropAddress});
await dgovObj.mintAirdropSupply(User1, '100', {from: airdropAddress});

// it should be total max supply (1 million DBIT).
await dgovObj.LockedBalance(User2).to.be(Web3.utils.toWei('1000000000', 'ether'));
// it should be total max supply (1 million DGOV).
expect(await dgovObj.getLockedBalance(User2)).to.be(Web3.utils.toWei('1000000000', 'ether'));
})


it('if the collateralised supply gets bigger than airdropped supply , there is no locked balance', async () => {

await dgovObj.setAirdroppedSupply('200', {from: deployer});
await dgovObj.mintAirdroppedSupply(User2, '100', {from: DBITAirdrop.address});
await dgovObj.mintAirdroppedSupply(User1, '100', {from: DBITAirdrop.address});
await dgovObj.setMaxAirdropSupply('200', {from: governance});
await dgovObj.mintAirdropSupply(User2, '100', {from: airdropAddress});
await dgovObj.mintAirdropSupply(User1, '100', {from: airdropAddress});

await dgovObj.mintCollateralisedSupply(User2, '10000000000000000000', {from: DBITAirdrop.address});
await dgovObj.mintCollateralisedSupply(User2, '100000000', {from: bankAddress});

await dgovObj.LockedBalance(User2).to.equal('0');
expect(await dgovObj.getLockedBalance(User2)).to.equal('0');


});

it(' directTransfer to another address ', async () => {


await dgovObj.mintCollateralisedSupply(bank, 300, {from: bank});
await dgovObj.mintCollateralisedSupply(exchange, 300, {from: exchange});
await dgovObj.mintAirdroppedSupply(Bank, 1000, {from: Bank});
await dgovObj.directTransfer(Bank, Exchange, 600, {from: Bank});
it(' transferFrom works between bankAddress and exchange contract', async () => {

await dgovObj.mintCollateralisedSupply(bankAddress, 300, {from: bankAddress});
await dgovObj.mintCollateralisedSupply(exchangeAddress, 300, {from: exchangeAddress});
await dgovObj.mintAirdropSupply(bankAddress, 1000, {from: bankAddress});
await dgovObj.transferFrom(bankAddress, exchangeAddress, 600, {from: bankAddress});
});


it('transfer is working between any general address', async () => {
await dgovObj.mintCollateralisedSupply(User1, 300, {from: bank});
await dgovObj.mintCollateralisedSupply(User2, 900, {from: bank})
await dgovObj.mintAllocatedSupply(User1, 300, {from: deployer});
await dgovObj.mintAllocatedSupply(User2, 800, {from: deployer})

await dgovObj.directTransfer(User1, User2, {from: deployer});


await dgovObj.mintCollateralisedSupply(User1, 300, {from: bankAddress});
await dgovObj.mintCollateralisedSupply(User2, 900, {from: bankAddress})
await dgovObj.mintAllocatedSupply(User1, 300, {from: governance});
await dgovObj.mintAllocatedSupply(User2, 800, {from: governance})
await dgovObj.transfer(User1, 100, {from: User2});
});


Expand Down

0 comments on commit 979262d

Please sign in to comment.