-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from JoinColony/feature/contract-loader-fs
Feature: contract-loader-fs
- Loading branch information
Showing
36 changed files
with
683 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/colony-js-contract-client/src/classes/ContractMethodMultisigSender.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# colonyJS Contract Loader for Node.js using the filesystem | ||
|
||
This package provides a means to load Ethereum smart contracts simply via | ||
the node `fs` module, for local testing and in dev environments | ||
|
||
## Installation | ||
|
||
``` | ||
yarn add @colony/colony-js-contract-loader-fs | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
// TODO DOCS | ||
Please see [the full documentation](https://joincolony.github.io/colonyjs/api-loaders/#INSERTCORRECTANCHORHERE). | ||
|
||
|
||
## Contributing | ||
|
||
This package is part of the [colonyJS monorepo](https://github.com/JoinColony/colonyJS). | ||
|
||
Please read our [contributing guidelines](https://github.com/JoinColony/colonyJS/blob/master/CONTRIBUTING.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"rootDir": "src", | ||
"collectCoverageFrom" : ["*.{js}", "**/*.{js}"], | ||
"coverageDirectory": "../coverage", | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 0 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"name": "@colony/colony-js-contract-loader-fs", | ||
"version": "1.0.0", | ||
"description": "Load Ethereum smart contract definitions/metadata from the filesystem (in node.js)", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"build": "yarn run build:flow && yarn run build:lib", | ||
"build:flow": "flow-copy-source src lib --ignore '__tests__/*.js'", | ||
"build:lib": "flow-remove-types --out-dir lib/ src/", | ||
"dev": "nodemon", | ||
"flow": "flow check", | ||
"lint": "eslint src", | ||
"precommit": "lint-staged", | ||
"test": "yarn run flow && yarn run lint && yarn run test:unit", | ||
"test:unit": "jest --coverage --config=jest.conf.json" | ||
}, | ||
"lint-staged": { | ||
"src/{,**/}*.js": [ | ||
"lint --fix", | ||
"git add" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/JoinColony/colonyJS.git" | ||
}, | ||
"contributors": [ | ||
"Christian Maniewski <[email protected]>", | ||
"Griffin Hotchkiss <[email protected]>", | ||
"James Lefrère <[email protected]>", | ||
"Jan Kaßel <[email protected]>", | ||
"Raul Glogovetan <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/JoinColony/colonyJS/issues" | ||
}, | ||
"homepage": "https://github.com/JoinColony/colonyJS#readme", | ||
"dependencies": { | ||
"@colony/colony-js-contract-loader": "^1.2.0", | ||
"jsonfile": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"flow-bin": "^0.72.0", | ||
"flow-copy-source": "^2.0.0", | ||
"flow-remove-types": "^1.2.3", | ||
"jest": "^22.4.0", | ||
"jest-sandbox": "^1.1.2", | ||
"nodemon": "^1.17.5" | ||
}, | ||
"engines": { | ||
"node": ">=8.2.1", | ||
"yarn": ">=1.3.2" | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/colony-js-contract-loader-fs/src/__tests__/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* eslint-env jest */ | ||
/* eslint no-underscore-dangle: 0 */ | ||
|
||
import createSandbox from 'jest-sandbox'; | ||
import FSLoader from '../loaders/FSLoader'; | ||
|
||
jest.mock('jsonfile', () => ({ | ||
readFile: jest.fn((file, cb) => | ||
cb(null, { | ||
address: '0x123', | ||
abi: [{ myData: 123 }], | ||
}), | ||
), | ||
})); | ||
|
||
describe('ContractFsLoader', () => { | ||
const sandbox = createSandbox(); | ||
const setupLoader = () => new FSLoader({ contractDir: '/tmp' }); | ||
|
||
const requiredProps = { | ||
address: true, | ||
abi: true, | ||
bytecode: false, | ||
}; | ||
|
||
beforeEach(() => { | ||
sandbox.clear(); | ||
}); | ||
|
||
test('Default implementation', async () => { | ||
const loader = setupLoader(); | ||
|
||
const query = { contractName: 'MyCoolContract' }; | ||
const { address, abi } = await loader.load(query, requiredProps); | ||
expect(address).toEqual('0x123'); | ||
expect(abi).toEqual([{ myData: 123 }]); | ||
}); | ||
|
||
test('Throws if contract name not given', async () => { | ||
const loader = setupLoader(); | ||
const query = { contractAddress: '0xdeafbeef' }; | ||
expect(loader.load(query, requiredProps)).rejects.toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* @flow */ | ||
|
||
import type { Transform } from '@colony/colony-js-contract-loader'; | ||
|
||
export type ConstructorArgs = { | ||
contractDir: string, | ||
transform: Transform, | ||
}; | ||
|
||
export type TruffleArtifact = { | ||
abi: Array<{}>, | ||
bytecode: string, | ||
networks: { | ||
[networkId: number]: { | ||
address: string, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* @flow */ | ||
|
||
const TruffleLoader = require('./loaders/TruffleLoader'); | ||
const FSLoader = require('./loaders/FSLoader'); | ||
|
||
exports.TruffleLoader = TruffleLoader; | ||
exports.FSLoader = FSLoader; |
53 changes: 53 additions & 0 deletions
53
packages/colony-js-contract-loader-fs/src/loaders/FSLoader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* @flow */ | ||
|
||
import type { | ||
ContractDefinition, | ||
IContractLoader, | ||
RequiredContractProps, | ||
Query, | ||
} from '@colony/colony-js-contract-loader'; | ||
|
||
import type { ConstructorArgs } from '../flowtypes'; | ||
|
||
const assert = require('assert'); | ||
const path = require('path'); | ||
const jsonfile = require('jsonfile'); | ||
|
||
const ContractLoader = require('@colony/colony-js-contract-loader').default; | ||
|
||
class FSLoader extends ContractLoader implements IContractLoader { | ||
_contractDir: string; | ||
|
||
constructor({ contractDir, transform }: ConstructorArgs = {}) { | ||
super({ transform }); | ||
assert( | ||
typeof contractDir === 'string' && contractDir, | ||
'A `contractDir` option must be provided', | ||
); | ||
this._contractDir = contractDir; | ||
} | ||
async _load( | ||
query: Query = {}, | ||
requiredProps?: RequiredContractProps, | ||
): Promise<?ContractDefinition> { | ||
const { contractName = '' } = query; | ||
|
||
assert(!!contractName, 'A `contractName` option must be provided'); | ||
|
||
const file = path.resolve(this._contractDir, `${contractName}.json`); | ||
return new Promise((resolve, reject) => { | ||
jsonfile.readFile(file, (error, contents) => { | ||
let transformed; | ||
if (error) return reject(error); | ||
try { | ||
transformed = this._transform(contents, query, requiredProps); | ||
} catch (transformError) { | ||
return reject(transformError); | ||
} | ||
return resolve(transformed); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = FSLoader; |
15 changes: 15 additions & 0 deletions
15
packages/colony-js-contract-loader-fs/src/loaders/TruffleLoader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* @flow */ | ||
|
||
import type { ConstructorArgs } from '../flowtypes'; | ||
|
||
const FSLoader = require('./FSLoader'); | ||
|
||
const { truffleTransform } = require('@colony/colony-js-contract-loader'); | ||
|
||
class TruffleLoader extends FSLoader { | ||
constructor({ contractDir }: ConstructorArgs = {}) { | ||
super({ transform: truffleTransform, contractDir }); | ||
} | ||
} | ||
|
||
module.exports = TruffleLoader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.