Skip to content

Commit

Permalink
Merge pull request #217 from tasitlabs/feature/gnosis-safe
Browse files Browse the repository at this point in the history
Gnosis Safe bootstrap
  • Loading branch information
pcowgill authored Feb 28, 2019
2 parents af167f6 + b929ebd commit 46b10e9
Show file tree
Hide file tree
Showing 76 changed files with 2,768 additions and 2,559 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"publish": "npm run clean:all && npm run bootstrap && npm test && npm run clean:3rd-parties && npx lerna publish",
"bootstrap": "npx lerna bootstrap --hoist",
"ganache:start:ropsten": "npx ganache-cli --fork https://ropsten.infura.io/latest --blockTime 0.1 -m 'beach swap combine paper music cook electric bullet trust actress liquid asthma' --gasLimit 1000000000000 --host 0.0.0.0 > /dev/null 2>&1 &",
"ganache:start": "npx ganache-cli -m 'beach swap combine paper music cook electric bullet trust actress liquid asthma' --gasLimit 1000000000 --host 0.0.0.0 > /dev/null 2>&1 &",
"ganache:start": "npx ganache-cli --noVMErrorsOnRPCResponse true -m 'beach swap combine paper music cook electric bullet trust actress liquid asthma' --gasLimit 1000000000 --host 0.0.0.0 > /dev/null 2>&1 &",
"ganache:stop": "kill `ps ax|grep ganache-cli|grep -v grep| awk '{print $1}'` 2> /dev/null; exit 0",
"truffle:migrate": "npx lerna run migrate --scope tasit-contracts",
"truffle:migrate": "npx lerna run migrate --scope tasit-contracts --stream",
"pretest": "npm run ganache:stop && npm run ganache:start && npm run truffle:migrate",
"test": "npx lerna run test",
"test": "npx lerna run test --stream --concurrency 1",
"posttest": "npm run ganache:stop"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/tasit-account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"scripts": {
"prepare": "npx babel src --out-dir dist --ignore **/*.test.js",
"test": "npm run lint && npx mocha src/*.test.js --require @babel/register",
"test": "npm run lint && npx mocha src/*.test.js --require @babel/register --file src/testHelpers/mochaSetup.js",
"lint": "npx prettier src/* --write"
},
"bugs": {
Expand All @@ -34,6 +34,6 @@
"@babel/preset-env": "^7.1.6",
"@babel/register": "^7.0.0",
"chai": "^4.2.0",
"mocha": "^6.0.1"
"mocha": "^6.0.2"
}
}
4 changes: 4 additions & 0 deletions packages/tasit-account/src/TasitAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import "ethers/dist/shims.js";
// shims aren't injected with package import
import { ethers } from "ethers";

// Account creates an ethres.js Wallet, should it create an Account object that encapsulates the wallet?
// TasitAcount.create()
// > Acount { wallet: ..., metaTxInfos..., etc }
// Related to: https://github.com/tasitlabs/TasitSDK/issues/220
const create = () => {
try {
const wallet = ethers.Wallet.createRandom();
Expand Down
17 changes: 6 additions & 11 deletions packages/tasit-account/src/ethers.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { expect, assert } from "chai";
import { ethers } from "ethers";

const zero = ethers.utils.bigNumberify(0);
const { ZERO } = constants;

let wallet, provider;
let wallet;

// Note: We're intentionally not testing the `fromEncryptedJson` or `encrypt` functions
// from `ethers.js` because we don't plan to expose that functionality in the Tasit SDK.
// For a detailed explanation of why, see this GitHub issue:
// https://github.com/tasitlabs/TasitSDK/issues/24#issuecomment-443576993
describe("ethers.js", () => {
beforeEach("instantiate wallet and provider objects", async function() {
provider = new ethers.providers.JsonRpcProvider();
provider.pollingInterval = 50;
beforeEach("instantiate wallet and provider objects", async () => {
[wallet] = accounts;
wallet = wallet.connect(provider);

const privateKey =
"0x11d943d7649fbdeb146dc57bd9cfc80b086bfab2330c7b25651dbaf382392f60";

wallet = new ethers.Wallet(privateKey, provider);
expect(wallet.address).to.have.lengthOf(42);
expect(wallet.provider).to.be.not.undefined;
});
Expand All @@ -39,7 +34,7 @@ describe("ethers.js", () => {
);

expect(fundedWalletBalance).not.to.be.undefined;
assert(emptyWalletBalance.eq(zero));
expect(`${emptyWalletBalance}`).to.equal(`${ZERO}`);
});

it("should sign a message", async () => {
Expand Down
35 changes: 35 additions & 0 deletions packages/tasit-account/src/testHelpers/mochaSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ethers } from "ethers";

// Chai
import { expect, assert } from "chai";
global.expect = expect;
//global.assert = assert;

// Helpers
import actionHelpers from "../../../tasit-action/dist/testHelpers/helpers";
global = Object.assign(global, actionHelpers);

// Global hooks
let snapshotId;

beforeEach("global beforeEach() hook", async () => {
const provider = new ethers.providers.JsonRpcProvider();
provider.pollingInterval = 50;
global.provider = provider;
snapshotId = await createSnapshot(provider);

while (snapshotId > 1) {
await revertFromSnapshot(provider, snapshotId--);
}

expect(snapshotId).to.equal(1);
});

afterEach("global afterEach() hook", async () => {
expect(snapshotId).to.equal(1);
await revertFromSnapshot(provider, snapshotId);

// Note: Without this the test suite is breaking.
// It is still unclear why
await mineBlocks(provider, 1);
});
6 changes: 2 additions & 4 deletions packages/tasit-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"scripts": {
"prepare": "rm -rf dist/* && npx babel src --out-dir dist --ignore src/*.test.js,src/**/*.test.js",
"test": "npm run lint && npx mocha \"src/**/*.test.js\" --recursive --require @babel/register --require src/testHelpers/mochaSetup.js --no-timeouts",
"test": "npm run lint && npx mocha \"src/**/*.test.js\" --recursive --require @babel/register --file src/testHelpers/mochaSetup.js",
"lint": "npx prettier src/* --write"
},
"bugs": {
Expand All @@ -34,11 +34,9 @@
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/preset-env": "^7.1.6",
"@babel/register": "^7.0.0",
"bn.js": "^4.11.8",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-bn": "^0.1.1",
"mocha": "^6.0.1",
"mocha": "^6.0.2",
"sinon": "^7.2.2",
"tasit-account": "^0.0.9"
}
Expand Down
9 changes: 5 additions & 4 deletions packages/tasit-action/src/TasitAction.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import ConfigLoader from "./ConfigLoader";
import Contract from "./contract/Contract";
import NFT from "./erc721/NFT";
import ERC721Full from "./erc721/ERC721Full";
import Land from "./erc721/Land";
import Decentraland from "./marketplace/Decentraland";
import Estate from "./erc721/Estate";
import Mana from "./erc20/Mana";
import ERC20Full from "./erc20/ERC20Full";

export { Contract, NFT, Land, Decentraland, Estate, Mana };
export { Contract, ERC721Full, Land, Decentraland, Estate, Mana };

export const ERC20 = { Mana };
export const ERC721 = { Land, Estate, NFT };
export const ERC20 = { Mana, ERC20Full };
export const ERC721 = { Land, Estate, ERC721Full };
export const Marketplace = { Decentraland };

export const TasitAction = {
Expand Down
4 changes: 4 additions & 0 deletions packages/tasit-action/src/contract/Contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export class Contract extends Subscription {
return this.#ethersContract.address;
};

getABI = () => {
return this.#ethersContract.interface.abi;
};

// For testing purposes
_getProvider = () => {
return this.#provider;
Expand Down
21 changes: 2 additions & 19 deletions packages/tasit-action/src/contract/Contract.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Contract from "./Contract";
import Account from "tasit-account";

// Note: SampleContract.json is originally generated by `tasit-contracts` and was pasted here manually
// See https://github.com/tasitlabs/TasitSDK/issues/45
import { abi as contractABI } from "../../../tasit-contracts/build/contracts/SampleContract.json";

// Note: Under the current `tasit-contracts` setup SampleContract aways will deployed with this address
Expand All @@ -12,8 +10,6 @@ const sampleContractAddress = "0x6C4A015797DDDd87866451914eCe1e8b19261931";
describe("TasitAction.Contract", () => {
let sampleContract;
let wallet;
let testcaseSnaphotId;
let provider;
let action;

beforeEach("should connect to an existing contract", async () => {
Expand All @@ -23,31 +19,20 @@ describe("TasitAction.Contract", () => {

sampleContract = undefined;
wallet = undefined;
testcaseSnaphotId = undefined;
provider = undefined;
action = undefined;

// Account creates a wallet, should it create an account object that encapsulates the wallet?
// TasitAcount.create()
// > Acount { wallet: ..., metaTxInfos..., etc }
wallet = createFromPrivateKey(
"0x11d943d7649fbdeb146dc57bd9cfc80b086bfab2330c7b25651dbaf382392f60"
);
[wallet] = accounts;

sampleContract = new Contract(sampleContractAddress, contractABI);
expect(sampleContract).to.exist;
expect(sampleContract.getAddress()).to.equal(sampleContractAddress);
expect(sampleContract.getValue).to.exist;
expect(sampleContract.setValue).to.exist;
expect(sampleContract._getProvider()).to.exist;

provider = sampleContract._getProvider();
testcaseSnaphotId = await createSnapshot(provider);
expect(sampleContract.getABI()).to.deep.equal(contractABI);
});

afterEach("revert blockchain snapshot", async () => {
await mineBlocks(provider, 1);

if (sampleContract) {
sampleContract.unsubscribe();

Expand All @@ -66,8 +51,6 @@ describe("TasitAction.Contract", () => {
"ethers.js should not be listening to any events."
).to.be.empty;
}

await revertFromSnapshot(provider, testcaseSnaphotId);
});

describe("should throw error when instantiated with invalid args", () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/tasit-action/src/erc20/ERC20Full.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Contract from "../contract/Contract";
import abi from "../../../tasit-contracts/abi/MyERC20Full.json";

export default class ERC20Full extends Contract {
constructor(address, wallet) {
super(address, abi, wallet);
}
}
13 changes: 13 additions & 0 deletions packages/tasit-action/src/erc20/ERC20Full.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ERC20Full from "./ERC20Full";

// Note: Under the current `tasit-contracts` setup ERC20Detailed aways will deployed with this address
// See https://github.com/tasitlabs/TasitSDK/issues/138
const ERC20_FULL_ADDRESS = "0x37E1A58dD465D33263D00185D065Ee36DD34CDb4";

describe("TasitAction.ERC20.ERC20Full", () => {
it("should get the ERC20Full name", async () => {
const erc20 = new ERC20Full(ERC20_FULL_ADDRESS);
const name = await erc20.name();
expect(name).to.equal("ERC20Full");
});
});
4 changes: 2 additions & 2 deletions packages/tasit-action/src/erc20/Mana.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Mana from "./Mana";

import { local as localAddresses } from "../../../tasit-contracts/decentraland/addresses";
import { local as localAddresses } from "../../../tasit-contracts/3rd-parties/decentraland/addresses";
const { MANAToken: MANA_ADDRESS } = localAddresses;

describe("TasitAction.Decentraland.Mana", () => {
it("should get the MANAToken name", async function() {
it("should get the MANAToken name", async () => {
const mana = new Mana(MANA_ADDRESS);
const name = await mana.name();
expect(name).to.equal("Decentraland MANA");
Expand Down
8 changes: 8 additions & 0 deletions packages/tasit-action/src/erc721/ERC721Full.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Contract from "../contract/Contract";
import abi from "../../../tasit-contracts/abi/MyERC721Full.json";

export default class ERC721Full extends Contract {
constructor(address, wallet) {
super(address, abi, wallet);
}
}
Loading

0 comments on commit 46b10e9

Please sign in to comment.