Skip to content

Commit 7872ba5

Browse files
committed
Fix deploy scripts and include as part of CI
1 parent ec8fb28 commit 7872ba5

File tree

5 files changed

+107
-70
lines changed

5 files changed

+107
-70
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ install:
1717
- yarn global add coveralls
1818
- yarn install
1919
script:
20-
- yarn run coverage && cat coverage/lcov.info | coveralls
20+
- yarn build
21+
- yarn deploy basic && yarn deploy extended && yarn deploy token
22+
- yarn coverage && cat coverage/lcov.info | coveralls
2123
- yarn test
2224
cache:
2325
yarn: true

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ $ ganache-cli --gasLimit 8000000
5252

5353
Then, to run tests:
5454
```sh
55-
$ yarn run coverage
5655
$ yarn test
57-
$ node scripts/gasAnalysis.js
58-
$ ./node_modules/.bin/solhint "contracts/**/*.sol"
56+
$ yarn coverage
57+
$ yarn linter
5958
```
6059

61-
Contracts may also be deployed locally using `$ node scripts/deploy.js`.
60+
A jurisdiction may then be deployed locally using `yarn deploy basic` or `yarn deploy extended`.
6261

6362
## API
6463
*NOTE: This documentation is still a work in progress. See the relevant contract source code for additional information.*

config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
module.exports = {
22
network: 'development',
33
TPLTokenAttributeID: 0,
4-
TPLTokenTotalSupply: 100,
5-
TPLTokenAttributeRestricted: false,
6-
TPLTokenAttributeMinimumRequiredStake: 0,
7-
TPLTokenAttributeJurisdictionFee: 0,
8-
TPLTokenAttributeDescription: 'Valid TPL token holder'
4+
TPLTokenTotalSupply: 100
95
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
},
1414
"scripts": {
1515
"build": "./node_modules/.bin/truffle compile",
16-
"test": "./node_modules/.bin/truffle compile compile && node scripts/testBasicDirect.js && node scripts/testExtendedDirect.js && node scripts/testBasicOnExtendedDirect.js && echo 'skipping scripts/testOptimizationDisabled.js'",
17-
"coverage": "./node_modules/.bin/solidity-coverage"
16+
"test": "./node_modules/.bin/truffle compile && node scripts/testBasicDirect.js && node scripts/testExtendedDirect.js && node scripts/testBasicOnExtendedDirect.js && echo 'skipping scripts/testOptimizationDisabled.js'",
17+
"coverage": "./node_modules/.bin/solidity-coverage",
18+
"linter": "./node_modules/.bin/solhint 'contracts/**/*.sol'",
19+
"deploy": "node scripts/deploy.js"
1820
}
1921
}

scripts/deploy.js

Lines changed: 96 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,108 @@
11
var fs = require('fs');
2-
3-
const JurisdictionContractData = require('../build/contracts/Jurisdiction.json')
4-
const TPLTokenContractData = require('../build/contracts/TPLToken.json')
52
const applicationConfig = require('../config.js')
63
const connectionConfig = require('../truffle.js')
7-
84
const connection = connectionConfig.networks[applicationConfig.network]
95

6+
const deployMetadataFilename = 'build/contractDeploymentAddresses.json'
7+
8+
let deployAddresses
9+
try {
10+
deployAddresses = require(`../${deployMetadataFilename}`)
11+
} catch(error) {
12+
deployAddresses = {}
13+
}
14+
15+
let deployType = process.argv[2] // Provide Basic or Extended jurisdiction type
16+
if (typeof(deployType) === 'undefined') {
17+
deployType = 'extended'
18+
} else {
19+
deployType = deployType.toLowerCase()
20+
}
21+
22+
let showAccounts = process.argv[3] // Provide if you'd like to dump accounts
23+
24+
const deployTypeOptions = new Set(['basic', 'extended', 'token'])
25+
if (!deployTypeOptions.has(deployType)) {
26+
console.error('must supply "basic", "extended", or "token" as the target!')
27+
process.exit(1)
28+
}
29+
30+
let args
31+
if (deployType === 'token') {
32+
const jurisdiction = deployAddresses.jurisdiction
33+
34+
if (typeof(jurisdiction) === 'undefined') {
35+
console.error('must first deploy a jurisdiction before attaching a token!')
36+
process.exit(1)
37+
}
38+
39+
args = [
40+
applicationConfig.TPLTokenTotalSupply,
41+
jurisdiction,
42+
applicationConfig.TPLTokenAttributeID
43+
]
44+
} else {
45+
args = []
46+
}
47+
48+
let contractImportLocation
49+
if (deployType === 'basic') {
50+
contractImportLocation = '../build/contracts/BasicJurisdiction.json'
51+
} else if (deployType === 'extended') {
52+
contractImportLocation = '../build/contracts/ExtendedJurisdiction.json'
53+
} else if (deployType === 'token') {
54+
contractImportLocation = '../build/contracts/TPLERC20RestrictedReceiverInstance.json'
55+
}
56+
57+
const ContractData = require(contractImportLocation)
58+
1059
let web3 = connection.provider
1160

12-
const Jurisdiction = new web3.eth.Contract(JurisdictionContractData.abi)
13-
const TPLToken = new web3.eth.Contract(TPLTokenContractData.abi)
14-
15-
const TPLTokenAttributeID = applicationConfig.TPLTokenAttributeID
16-
const TPLTokenTotalSupply = applicationConfig.TPLTokenTotalSupply
17-
const TPLTokenAttributeRestricted = applicationConfig[
18-
'TPLTokenAttributeRestricted'
19-
]
20-
const TPLTokenAttributeMinimumRequiredStake = applicationConfig[
21-
'TPLTokenAttributeMinimumRequiredStake'
22-
]
23-
const TPLTokenAttributeJurisdictionFee = applicationConfig[
24-
'TPLTokenAttributeJurisdictionFee'
25-
]
26-
const TPLTokenAttributeDescription = applicationConfig[
27-
'TPLTokenAttributeDescription'
28-
]
61+
const Contract = new web3.eth.Contract(ContractData.abi)
2962

3063
async function main() {
31-
console.log('deploying jurisdiction & mock TPLToken...')
32-
let deployAddresses = {}
33-
const deployMetadataFilename = 'build/contractDeploymentAddresses.json'
34-
const addresses = await Promise.resolve(web3.eth.getAccounts())
35-
if (addresses.length === 0) {
36-
console.log('cannot find any addresses...')
37-
return false
64+
console.log(
65+
`deploying ${
66+
deployType
67+
}${
68+
deployType !== 'token' ? ' jurisdiction' : ''
69+
} to ${
70+
applicationConfig.network
71+
} network...`
72+
)
73+
74+
const accounts = await Promise.resolve(web3.eth.getAccounts())
75+
if (accounts.length === 0) {
76+
console.error('cannot find any accounts...')
77+
process.exit(1)
3878
}
3979

40-
const address = addresses[0]
41-
deployAddresses.owner = address
42-
console.log(` owner: ${address}`)
43-
44-
const JurisdictionContractInstance = await Jurisdiction.deploy({
45-
data: JurisdictionContractData.bytecode
46-
}).send({
47-
from: address,
48-
gas: 5000000,
49-
gasPrice: '1000000000'
50-
})
80+
const account = accounts[0]
81+
if (deployType !== 'token') {
82+
deployAddresses.jurisdictionOwner = account
83+
} else {
84+
deployAddresses.tokenOwner = account
85+
}
86+
87+
console.log(` deployed by: ${account}`)
5188

52-
const jurisdictionAddress = JurisdictionContractInstance.options.address
53-
deployAddresses.jurisdiction = jurisdictionAddress
54-
console.log(` jurisdiction: ${jurisdictionAddress}`)
55-
56-
const TPLTokenContractInstance = await TPLToken.deploy({
57-
data: TPLTokenContractData.bytecode,
58-
arguments: [
59-
JurisdictionContractInstance.options.address,
60-
TPLTokenAttributeID,
61-
TPLTokenTotalSupply
62-
]
89+
const ContractInstance = await Contract.deploy({
90+
data: ContractData.bytecode,
91+
arguments: args
6392
}).send({
64-
from: address,
65-
gas: 5000000,
66-
gasPrice: '1000000000'
93+
from: account,
94+
gas: 7000000,
95+
gasPrice: '10000000000'
6796
})
6897

69-
const tokenAddress = TPLTokenContractInstance.options.address
70-
deployAddresses.token = tokenAddress
71-
console.log(`mock TPL token: ${tokenAddress}`)
98+
const deployedAddress = ContractInstance.options.address
99+
if (deployType !== 'token') {
100+
deployAddresses.jurisdiction = deployedAddress
101+
console.log(` jurisdiction: ${deployedAddress}`)
102+
} else {
103+
deployAddresses.token = deployedAddress
104+
console.log(` mock token: ${deployedAddress}`)
105+
}
72106

73107
fs.writeFile(
74108
deployMetadataFilename,
@@ -77,10 +111,14 @@ async function main() {
77111
err => {
78112
if (err) {
79113
console.error(err)
80-
process.exit()
114+
process.exit(1)
81115
}
82116
console.log(`metadata written to ${deployMetadataFilename}`)
83-
process.exit()
117+
if (showAccounts === 'verbose') {
118+
console.log()
119+
console.log(JSON.stringify(deployAddresses, null, 2))
120+
}
121+
process.exit(0)
84122
}
85123
)
86124
}

0 commit comments

Comments
 (0)