Skip to content

Commit 7d69cb4

Browse files
authored
Add deployment helper (#28)
* feat: add deployment address helper * chore: update lock file * chore: add address check & bump version * chore: remove mocha * feat: add jest test to package json * fix: add leading slash for types folder ignore * add exports * chore: remove async
1 parent 040463f commit 7d69cb4

File tree

8 files changed

+21500
-13965
lines changed

8 files changed

+21500
-13965
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ coverage/
55
coverage.json
66
.idea
77
build
8-
types
9-
types-ts
8+
/types
9+
/types-ts
1010
test
1111
.DS_STORE
1212
.env

jest.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
moduleFileExtensions: ['js', 'json', 'ts'],
3+
rootDir: './',
4+
testEnvironment: 'node',
5+
testRegex: '.*\\.spec\\.ts$',
6+
transform: {
7+
'^.+\\.tsx?$': 'ts-jest',
8+
},
9+
collectCoverageFrom: ['src/**/*.(t|j)s'],
10+
coverageReporters:
11+
process.env.CI === 'true'
12+
? ['text-summary', 'cobertura']
13+
: ['lcov'],
14+
coveragePathIgnorePatterns: ['<rootDir>/node_modules/'],
15+
coverageDirectory: 'coverage',
16+
transformIgnorePatterns: []
17+
};

package-lock.json

Lines changed: 21396 additions & 13949 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@spherity/ethr-revocation-registry",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "The Ethereum Revocation List types for smart contract interaction.",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -17,8 +17,10 @@
1717
"compile-src": "tsc -p tsconfig.src.json --outDir ./dist/",
1818
"migrate": "tsc -p ./tsconfig.migrate.json --outDir ./migrations && npm run compile && truffle migrate",
1919
"migrate-goerli": "tsc -p ./tsconfig.migrate.json --outDir ./migrations && npm run compile && truffle migrate --network goerli",
20-
"test": "npx truffle test",
20+
"test": "npm run test:jest && npm run test:truffle",
21+
"test:truffle": "npx truffle test",
2122
"test:coverage": "npx truffle run coverage",
23+
"test:jest": "jest",
2224
"compile": "npx truffle compile && apply-registry"
2325
},
2426
"files": [
@@ -59,7 +61,7 @@
5961
"@types/bn.js": "^4.11.6",
6062
"@types/chai": "^4.2.11",
6163
"@types/chai-as-promised": "^7.1.5",
62-
"@types/mocha": "^7.0.2",
64+
"@types/jest": "^28.0.8",
6365
"@types/web3": "^1.2.2",
6466
"chai-as-promised": "^7.1.1",
6567
"eth-gas-reporter": "^0.2.25",
@@ -72,7 +74,9 @@
7274
"web3": "^1",
7375
"web3-core": "^1",
7476
"web3-eth-contract": "^1",
75-
"web3-utils": "^1"
77+
"web3-utils": "^1",
78+
"jest": "^29.1.2",
79+
"ts-jest": "^29.0.3"
7680
},
7781
"dependencies": {
7882
"@openzeppelin/contracts": "^4.7.3",

src/deployments.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {getDeployments} from "./deployments";
2+
3+
describe('Deployments', () => {
4+
it('should get deployments for chainId 5', async () => {
5+
await getDeployments(5)
6+
})
7+
8+
it('should throw an error getting deployments for chainId 999999', async () => {
9+
try {
10+
await getDeployments(999999)
11+
} catch(error: any) {
12+
if(error.message !== "There was a problem reading the deployment file for chainId '999999'") {
13+
throw new Error("Unexpected error in test")
14+
}
15+
}
16+
})
17+
})

src/deployments.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {NetworkDeployment} from "./types/NetworkDeployment";
2+
3+
const NETWORK_PATH = "../networks/"
4+
5+
export function getDeployments(chainId: number): NetworkDeployment[] {
6+
try{
7+
return require(NETWORK_PATH + chainId + ".json")
8+
} catch(error) {
9+
throw new Error(`There was a problem reading the deployment file for chainId '${chainId}'`)
10+
}
11+
}
12+
13+
export function getRevocationRegistryDeployment(chainId: number): NetworkDeployment {
14+
try{
15+
const deployments = getDeployments(chainId)
16+
if(typeof deployments === 'undefined' || deployments.length === 0) {
17+
throw new Error(`No deployments found for chainId ${chainId}`)
18+
}
19+
const deployment = deployments.find(deployment => deployment.contractName === "RevocationRegistry")
20+
if(typeof deployment === 'undefined') {
21+
throw new Error(`No Revocation Registry deployment found for chainId ${chainId}`)
22+
}
23+
return deployment
24+
} catch(error) {
25+
throw new Error(`There was a problem reading the deployment file for chainId '${chainId}: ${error}'`)
26+
}
27+
}
28+
29+
export function getRevocationRegistryDeploymentAddress(chainId: number): string {
30+
const registry = getRevocationRegistryDeployment(chainId)
31+
if(typeof registry.address === 'undefined' || registry.address !== "") {
32+
throw new Error("Contract address has not been found")
33+
}
34+
return registry.address
35+
}

src/index.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
export {
2-
EIP712DomainName,
3-
EIP712ChangeStatusType,
4-
EIP712ChangeStatusDelegatedType,
5-
EIP712ChangeStatusesInListType,
6-
EIP712ChangeStatusesInListDelegatedType,
7-
EIP712ChangeListOwnerType,
8-
EIP712AddListDelegateType,
9-
EIP712RemoveListDelegateType,
10-
EIP712ChangeListStatusType,
11-
} from "./util"
2+
EIP712DomainName,
3+
EIP712ChangeStatusType,
4+
EIP712ChangeStatusDelegatedType,
5+
EIP712ChangeStatusesInListType,
6+
EIP712ChangeStatusesInListDelegatedType,
7+
EIP712ChangeListOwnerType,
8+
EIP712AddListDelegateType,
9+
EIP712RemoveListDelegateType,
10+
EIP712ChangeListStatusType,
11+
} from "./util"
12+
13+
export {
14+
getDeployments,
15+
getRevocationRegistryDeployment,
16+
getRevocationRegistryDeploymentAddress
17+
} from "./deployments"
18+
19+
export {
20+
NetworkDeployment
21+
} from "./types/NetworkDeployment"

src/types/NetworkDeployment.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type NetworkDeployment = {
2+
contractName: string
3+
address: string
4+
transactionHash: string
5+
}

0 commit comments

Comments
 (0)