Skip to content

Testing buidler #10

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed ._.env.default
Binary file not shown.
14 changes: 2 additions & 12 deletions .env.default
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
# Private key must be prepended by '0x'
DEPLOYMENT_PRIVATE_KEY="0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d"

# The constants you'd like to deploy with (production, staging, development)
# Use production for circleCI as we want to test production configurations on test-net in our scenario tests
DEPLOYMENT_CONSTANT="production"

# Deployment network can be 1 (main-net), 42 (kovan), 50 (test-rpc)
DEPLOYMENT_NETWORK_ID=50;

# If you're deploying to any live network (main-net/test-net), make sure this is filled out
INFURA_KEY=""
# IS DEVELOPMENT AND USING BUIDLER
IS_BUIDLER=false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/artifacts/json
/artifacts/ts
/build
/cache
/dist
/node_modules
/transpiled
Expand Down
26 changes: 26 additions & 0 deletions buidler.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BuidlerConfig, usePlugin } from "@nomiclabs/buidler/config";

usePlugin("@nomiclabs/buidler-truffle5");
usePlugin("@nomiclabs/buidler-web3");

const config: BuidlerConfig = {
solc: {
version: "0.5.7",
optimizer: {
enabled: true,
runs: 200
},
evmVersion: "byzantium"
},
paths: {
artifacts: './build/contracts',
tests: './transpiled/test/contracts'
},
networks: {
buidlerevm: {
blockGasLimit: 20000000
}
}
};

export default config;
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"name": "set-protocol-contract-utils",
"version": "1.0.3",
"main": "dist/artifacts/index.js",
Expand All @@ -20,6 +20,8 @@
"chain": "yarn clean-chain && ganache-cli --db blockchain --networkId 50 --accounts 20 -l 20000000 -e 10000000000 -m 'concert load couple harbor equip island argue ramp clarify fence smart topic'",
"clean": "rm -rf build; rm -rf transpiled; rm -rf types/generated",
"clean-chain": "rm -rf blockchain && cp -r snapshots/0x-Kyber-Compound blockchain",
"buidler-test": "buidler compile && yarn buidler-setup && yarn transpile && buidler test",
"buidler-setup": "bash scripts/buidler_deploy_dev.sh && yarn transformJson && yarn generate-typings",
"compile": "./node_modules/.bin/truffle compile --all",
"coverage": "yarn coverage-setup && ./node_modules/.bin/solidity-coverage && yarn coverage-cleanup",
"coverage-cleanup": "find artifacts/ts -name \\*.js* -type f -delete && find test -name \\*.js* -type f -delete && find types -name \\*.js* -type f -delete && find utils -name \\*.js* -type f -delete",
Expand Down Expand Up @@ -54,6 +56,7 @@
"@0xproject/types": "^1.0.1-rc.4",
"@0xproject/utils": "^2.0.2",
"@0xproject/web3-wrapper": "^1.1.2",
"@truffle/contract": "^4.0.2",
"@types/bignumber.js": "^4.0.3",
"@types/expect": "^1.20.4",
"@types/fs-extra": "^5.0.0",
Expand All @@ -80,16 +83,18 @@
"solc": "^0.5.4",
"solidity-coverage": "^0.6.3",
"truffle": "^5.1.12",
"@truffle/contract": "^4.0.2",
"tslint": "^5.8.0",
"tslint-no-unused-expression-chai": "0.0.3",
"types-ethereumjs-util": "^0.0.5",
"typescript": "^3.3.1"
},
"dependencies": {
"@nomiclabs/buidler": "^1.3.3",
"@nomiclabs/buidler-truffle5": "^1.3.4-rc.0",
"@nomiclabs/buidler-web3": "^1.3.4-rc.0",
"bn-chai": "^1.0.1",
"canonical-weth": "^1.3.1",
"dotenv": "^6.2.0",
"dotenv": "^8.2.0",
"eth-gas-reporter": "^0.1.10",
"ethlint": "^1.2.3",
"expect": "^24.1.0",
Expand Down
49 changes: 49 additions & 0 deletions scripts/buidler_deploy_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# NOTE: This script is intended for use by external repos that depend
# on the Set Protocol smart contracts in any capacity. To deploy the Set Protocol
# smart contracts on your local blockchain environment,
# you can call this script, which will deploy the smart contracts
# to your local chain and subsequently *locally* update the artifacts exported by
# the package to reflect the newly deployed contracts' addresses.
#
# The build/ directory is used for day-to-day development environment
# environment, whereas the artifacts/ directory is to store production
# artifacts (i.e. artifacts which we publish in the contracts
# NPM package).
#
# Truffle will by default use the build folder to fetch the most recent
# artifacts and update them with the newly deployed contract
# addresses, saving the newest artifacts in build.
#
# Thus, when pushing a new build to a development network, we want to replace build
# folder with most recent saved production artifacts/ directory contents
# so that our new artifacts include the addresses of contracts deployed in production
# on networks *other* than development.

rm -rf transpiled

rm -rf types/generated

# Replace production artifacts with newly generated json artifacts
rm artifacts/json/*

mkdir artifacts/ts
mkdir artifacts/json

cp build/contracts/* artifacts/json/

# Remove old transpiled artifacts from the artifacts/ directory
rm -rf artifacts/ts/*

# Transform raw JSON artifacts into Typescript modules. This makes
# interacting with the artifacts significantly easier when exporting
# them as modules.
for filename in build/contracts/*.json; do
filename_base=$(basename $filename .json)

# Add export lines to artifacts/ts/index.ts so types will works
echo -e "export { $filename_base } from \"./$filename_base\";" >> artifacts/ts/index.ts
done

echo -e "Successfully deployed contracts onto Development Testnet!"
11 changes: 4 additions & 7 deletions test/contracts/lib/bytes32Library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ contract('Bytes32Mock', accounts => {

let bytes32Library: Bytes32LibraryMockContract;

before(async () => {
bytes32Library = await libraryMockHelper.deployBytes32LibraryAsync();
});

describe('#testBytes32ToBytes', async () => {
let subjectString: string;
let subjectData: Bytes;

beforeEach(async () => {
bytes32Library = await libraryMockHelper.deployBytes32LibraryAsync();
});

async function subject(data: Bytes): Promise<string> {
return bytes32Library.testBytes32ToBytes.callAsync(
Expand Down Expand Up @@ -58,10 +59,6 @@ contract('Bytes32Mock', accounts => {
let subjectString: string;
let subjectData: Bytes;

beforeEach(async () => {
bytes32Library = await libraryMockHelper.deployBytes32LibraryAsync();
});

async function subject(data: Bytes): Promise<string> {
return bytes32Library.testBytes32ToString.callAsync(
subjectData,
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/lib/commonValidationsLibrary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract('CommonValidationsLibrary', accounts => {

let commonValidationsMockLibrary: CommonValidationsLibraryMockContract;

beforeEach(async () => {
before(async () => {
commonValidationsMockLibrary = await libraryMockHelper.deployCommonValidationsLibraryAsync();
});

Expand Down
10 changes: 9 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@
"types/**/*.ts",
"utils/**/*.ts",
"test/**/*.ts"
]
],
"files": [
"./buidler.config.ts",
"./node_modules/@nomiclabs/buidler-web3/src/type-extensions.d.ts",
"./node_modules/@nomiclabs/buidler-truffle5/src/type-extensions.d.ts"
],
"compilerOptions": {
"skipLibCheck": true
}
}
8 changes: 0 additions & 8 deletions types/contract_templates/contract.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ export class {{contractName}}Contract extends BaseContract {
wrapper.address = newContractInstance.options.address;
});
}
static async deployed(web3: Web3, defaults: Tx): Promise<{{contractName}}Contract> {
const web3Utils = new Web3Utils(web3);
const currentNetwork = await web3Utils.getNetworkIdAsync();
const { abi, networks }: { abi: any[]; networks: any } = ContractArtifacts;
const web3ContractInstance = new web3.eth.Contract(abi, networks[currentNetwork].address);

return new {{contractName}}Contract(web3ContractInstance, defaults);
}
static async at(
address: string,
web3: Web3,
Expand Down
8 changes: 6 additions & 2 deletions utils/web3Helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Web3 = require('web3'); // import web3 v1.0 constructor
const BigNumber = require('bignumber.js');
require('dotenv').config({ path: './.env'});
import { version } from '../package.json';
import { Address } from 'set-protocol-utils';
import { DEFAULT_GAS, NULL_ADDRESS } from './constants';
Expand Down Expand Up @@ -45,12 +46,15 @@ export const linkLibrariesToDeploy = async (contract: any, libraries: any[], fro
contract.setNetwork(50);

await Promise.all(libraries.map(async library => {
console.log(library.contractName);
const truffleLibrary = await library.new(
{ from },
);

await contract.link(library.contractName, truffleLibrary.address);
if (process.env.IS_BUIDLER === 'true') {
await contract.link(truffleLibrary);
} else {
await contract.link(library.contractName, truffleLibrary.address);
}
}));
};

Expand Down
Loading