Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/dependencies #198

Merged
merged 22 commits into from Jul 31, 2019
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Fixing issues from updated changes.

  • Loading branch information
Freydal committed Jul 29, 2019
commit 393b302d845ac16cb5082089205bb45e7a16d288
@@ -30,7 +30,6 @@ if (args["test-mnemonic"] || !mnemonic) {
const networkId = await web3.eth.net.getId();

const kosuToken = new KosuTokenContract(
artifacts.KosuToken.compilerOutput.abi,
DeployedAddresses[networkId].KosuToken,
provider,
);
@@ -1,12 +1,13 @@
import { BlockchainLifecycle } from "@0x/dev-utils";
import { MnemonicWalletSubprovider, RPCSubprovider } from "@0x/subproviders";
import { providerUtils } from "@0x/utils";
import {provider} from 'web3-providers';
import { Web3Wrapper } from "@0x/web3-wrapper";
import fs from "fs";
import safeRequire from "safe-node-require";
import Web3 from "web3";
import Web3ProviderEngine from "web3-provider-engine";
import { BN, toWei } from "web3-utils";
import { toWei } from "web3-utils";
import yargs from "yargs";

import * as deployedAddresses from "../deployedAddresses.json";
@@ -27,14 +28,14 @@ if (args["test-mnemonic"] || !mnemonic) {
(async () => {
const mnemonicSubprovider = mnemonic ? new MnemonicWalletSubprovider({ mnemonic }) : null;
const rpcSubprovider = new RPCSubprovider(args["rpc-url"]);
const provider = new Web3ProviderEngine();
const providerEngine = new Web3ProviderEngine();
if (mnemonicSubprovider) {
provider.addProvider(mnemonicSubprovider);
providerEngine.addProvider(mnemonicSubprovider);
}
provider.addProvider(rpcSubprovider);
providerUtils.startProviderEngine(provider);
providerEngine.addProvider(rpcSubprovider);
providerUtils.startProviderEngine(providerEngine);

const web3 = new Web3(provider);
const web3 = new Web3(providerEngine as unknown as provider);

const normalizedFromAddress = await web3.eth.getCoinbase().then((x: string) => x.toLowerCase());

@@ -54,7 +55,7 @@ if (args["test-mnemonic"] || !mnemonic) {
}
}

const migratedContracts = await migrations(provider, txDefaults, {});
const migratedContracts = await migrations(providerEngine, txDefaults, {});

const contracts = {};
for (const contractKey of Object.keys(migratedContracts)) {
@@ -1,4 +1,4 @@
import Decoder from "web3-eth-abi";
const Decoder: any = require('web3-eth-abi');
import { hexToNumberString, soliditySha3 } from "web3-utils";

import * as EventEmitter from "../generated-artifacts/EventEmitter.json";
@@ -2,7 +2,7 @@ import { getContractAddressesForNetworkOrThrow } from "@0x/contract-addresses";
import { Web3Wrapper } from "@0x/web3-wrapper";
import { ContractArtifact } from "ethereum-types";
import Web3ProviderEngine from "web3-provider-engine";
import { BN, toWei } from "web3-utils";
import { toWei } from "web3-utils";

import {
artifacts,
@@ -255,17 +255,17 @@ export class TestHelpers {
}
}

public async variablePoll(start: number, end: number): Promise<{ blockNumber: number; pollId: number }> {
public async variablePoll(start: number, end: number): Promise<{ blockNumber: number; pollId: BigNumber }> {
const base = await this.web3Wrapper.getBlockNumberAsync();
const creationBlock = base + 1;
const commitEnd = creationBlock + start;
const revealEnd = commitEnd + end;
const { logs, blockNumber } = await this.migratedContracts.voting.createPoll.awaitTransactionSuccessAsync(
commitEnd,
revealEnd,
new BigNumber(commitEnd),
new BigNumber(revealEnd),
);
const { pollId } = decodeKosuEvents(logs)[0];
return { blockNumber, pollId };
return { blockNumber, pollId: new BigNumber(pollId) };
}
}

@@ -90,11 +90,11 @@ before(async () => {
const contracts = (await migrations(provider, txDefaults, { noLogs: true })) as MigratedTestContracts;
contracts.basicTradeSubContract = await BasicTradeSubContractContract.deployFrom0xArtifactAsync(
artifacts.BasicTradeSubContract as ContractArtifact,
web3.currentProvider,
provider,
txDefaults,
JSON.stringify(argumentsJson),
);
contracts.kosuToken.bondTokens.awaitTransactionSuccessAsync("0", { value: TestValues.oneEther.times(85) });
contracts.kosuToken.bondTokens.awaitTransactionSuccessAsync(TestValues.zero, { value: TestValues.oneEther.times(85) });
if (!useGeth) {
web3.eth.personal.importRawKey(
"0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d",
@@ -41,38 +41,36 @@ describe("PosterRegistry", () => {

describe("registerTokens", () => {
it("should require a balance greater or equal to the amount registered", async () => {
const value = toWei("50");
const from = accounts[1];

await token.balanceOf
.callAsync(from)
.then(x => x.toString())
.should.eventually.eq("0");
await posterRegistry.registerTokens.awaitTransactionSuccessAsync(value, { from }).should.eventually.be
await posterRegistry.registerTokens.awaitTransactionSuccessAsync(TestValues.oneHundredEther, { from }).should.eventually.be
.rejected;
});

it("should require an approval greater or equal to the amount registered", async () => {
const value = toWei("50");
const from = accounts[0];

await token.balanceOf
.callAsync(from)
.then(x => x.toString())
.then(parseInt)
.should.eventually.gt(parseInt(value));
await token.approve.awaitTransactionSuccessAsync(treasury.address, toBN("0")).should.eventually.be
.should.eventually.gt(parseInt(TestValues.oneHundredEther));
await token.approve.awaitTransactionSuccessAsync(treasury.address, TestValues.zero).should.eventually.be
.fulfilled;
await token.allowance
.callAsync(from, treasury.address)
.then(x => x.toString())
.should.eventually.eq("0");
await posterRegistry.registerTokens.awaitTransactionSuccessAsync(value).should.eventually.be.rejected;
await posterRegistry.registerTokens.awaitTransactionSuccessAsync(TestValues.oneHundredEther).should.eventually.be.rejected;
});

it("should increase tokensContributed and tokensRegisteredFor by the amount", async () => {
const value = toWei("50");
const double = toWei("100");
const value = new BigNumber(toWei("50"));
const double = TestValues.oneHundredEther;
const from = accounts[0];

await token.approve.awaitTransactionSuccessAsync(treasury.address, value);
@@ -81,29 +79,29 @@ describe("PosterRegistry", () => {
await posterRegistry.tokensRegisteredFor
.callAsync(from)
.then(x => x.toString())
.should.eventually.eq(value);
.should.eventually.eq(value.toString());
await posterRegistry.tokensContributed
.callAsync()
.then(x => x.toString())
.should.eventually.eq(value);
.should.eventually.eq(value.toString());

await token.approve.awaitTransactionSuccessAsync(treasury.address, value);
await posterRegistry.registerTokens.awaitTransactionSuccessAsync(value);

await posterRegistry.tokensRegisteredFor
.callAsync(from)
.then(x => x.toString())
.should.eventually.eq(double);
.should.eventually.eq(double.toString());
await posterRegistry.tokensContributed
.callAsync()
.then(x => x.toString())
.should.eventually.eq(double);
.should.eventually.eq(double.toString());
});
});

describe("releaseTokens", () => {
it("should not allow you to reduce balance below 0", async () => {
const amount = toWei("1");
const amount = TestValues.oneEther;
const from = accounts[0];

await cleanupUser(from);
@@ -117,8 +115,8 @@ describe("PosterRegistry", () => {
});

it("should reduce balance and total by the amount", async () => {
const value = toWei("50");
const double = toWei("100");
const value = new BigNumber(toWei("50"));
const double = TestValues.oneHundredEther;
const from = accounts[0];

await token.approve.awaitTransactionSuccessAsync(treasury.address, double);
@@ -127,26 +125,26 @@ describe("PosterRegistry", () => {
await posterRegistry.tokensRegisteredFor
.callAsync(from)
.then(x => x.toString())
.should.eventually.eq(double);
.should.eventually.eq(double.toString());
await posterRegistry.tokensContributed
.callAsync()
.then(x => x.toString())
.should.eventually.eq(double);
.should.eventually.eq(double.toString());

await posterRegistry.releaseTokens.awaitTransactionSuccessAsync(value, { from });

await posterRegistry.tokensRegisteredFor
.callAsync(from)
.then(x => x.toString())
.should.eventually.eq(value);
.should.eventually.eq(value.toString());
await posterRegistry.tokensContributed
.callAsync()
.then(x => x.toString())
.should.eventually.eq(value);
.should.eventually.eq(value.toString());
});

it("should return the tokens to the user's treasury currentBalance", async () => {
const value = toWei("50");
const value = new BigNumber(toWei("50"));
const from = accounts[0];

await token.approve.awaitTransactionSuccessAsync(treasury.address, value);
@@ -161,7 +159,7 @@ describe("PosterRegistry", () => {
afterBalance
.minus(initialBalance)
.toString()
.should.eq(value);
.should.eq(value.toString());
});
});

@@ -173,7 +171,7 @@ describe("PosterRegistry", () => {

describe("tokensRegisteredFor", () => {
it("should return the current registered tokens for user", async () => {
const value = toWei("50");
const value = new BigNumber(toWei("50"));
const from = accounts[0];

await cleanupUser(from);
@@ -184,13 +182,13 @@ describe("PosterRegistry", () => {
await posterRegistry.tokensRegisteredFor
.callAsync(from)
.then(x => x.toString())
.should.eventually.eq(value);
.should.eventually.eq(value.toString());
});
});

describe("tokensContributed", () => {
it("should report tokensContributed", async () => {
const value = toWei("50");
const value = new BigNumber(toWei("50"));
const from = accounts[0];

await cleanupUser(from);
@@ -201,11 +199,11 @@ describe("PosterRegistry", () => {
await posterRegistry.tokensContributed
.callAsync()
.then(x => x.toString())
.should.eventually.eq(value);
.should.eventually.eq(value.toString());
});

it("should match tokens possessed by contract", async () => {
const value = toWei("50");
const value = new BigNumber(toWei("50"));
const from = accounts[0];

await cleanupUser(from);
@@ -216,17 +214,17 @@ describe("PosterRegistry", () => {
await posterRegistry.tokensContributed
.callAsync()
.then(x => x.toString())
.should.eventually.eq(value);
.should.eventually.eq(value.toString());
await token.balanceOf
.callAsync(posterRegistry.address)
.then(x => x.toString())
.should.eventually.eq(value);
.should.eventually.eq(value.toString());
});
});

describe("PosterRegistryUpdate", () => {
it("should emit event when tokens are registered", async () => {
const value = toWei("50");
const value = new BigNumber(toWei("50"));
const from = accounts[0];

await cleanupUser(from);
@@ -237,11 +235,11 @@ describe("PosterRegistry", () => {

decodedLogs.eventType.should.eq("PosterRegistryUpdate");
decodedLogs.poster.should.eq(from.toLowerCase());
decodedLogs.stake.should.eq(value);
decodedLogs.stake.should.eq(value.toString());
});

it("should emit event when tokens are released", async () => {
const value = toWei("50");
const value = new BigNumber(toWei("50"));
const from = accounts[0];

await cleanupUser(from);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.