Skip to content

Commit

Permalink
Add deployment helper (#28)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fermentfan authored Oct 11, 2022
1 parent 040463f commit 7d69cb4
Show file tree
Hide file tree
Showing 8 changed files with 21,500 additions and 13,965 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ coverage/
coverage.json
.idea
build
types
types-ts
/types
/types-ts
test
.DS_STORE
.env
Expand Down
17 changes: 17 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: './',
testEnvironment: 'node',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
collectCoverageFrom: ['src/**/*.(t|j)s'],
coverageReporters:
process.env.CI === 'true'
? ['text-summary', 'cobertura']
: ['lcov'],
coveragePathIgnorePatterns: ['<rootDir>/node_modules/'],
coverageDirectory: 'coverage',
transformIgnorePatterns: []
};
35,345 changes: 21,396 additions & 13,949 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spherity/ethr-revocation-registry",
"version": "1.0.8",
"version": "1.0.9",
"description": "The Ethereum Revocation List types for smart contract interaction.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand All @@ -17,8 +17,10 @@
"compile-src": "tsc -p tsconfig.src.json --outDir ./dist/",
"migrate": "tsc -p ./tsconfig.migrate.json --outDir ./migrations && npm run compile && truffle migrate",
"migrate-goerli": "tsc -p ./tsconfig.migrate.json --outDir ./migrations && npm run compile && truffle migrate --network goerli",
"test": "npx truffle test",
"test": "npm run test:jest && npm run test:truffle",
"test:truffle": "npx truffle test",
"test:coverage": "npx truffle run coverage",
"test:jest": "jest",
"compile": "npx truffle compile && apply-registry"
},
"files": [
Expand Down Expand Up @@ -59,7 +61,7 @@
"@types/bn.js": "^4.11.6",
"@types/chai": "^4.2.11",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^7.0.2",
"@types/jest": "^28.0.8",
"@types/web3": "^1.2.2",
"chai-as-promised": "^7.1.1",
"eth-gas-reporter": "^0.2.25",
Expand All @@ -72,7 +74,9 @@
"web3": "^1",
"web3-core": "^1",
"web3-eth-contract": "^1",
"web3-utils": "^1"
"web3-utils": "^1",
"jest": "^29.1.2",
"ts-jest": "^29.0.3"
},
"dependencies": {
"@openzeppelin/contracts": "^4.7.3",
Expand Down
17 changes: 17 additions & 0 deletions src/deployments.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {getDeployments} from "./deployments";

describe('Deployments', () => {
it('should get deployments for chainId 5', async () => {
await getDeployments(5)
})

it('should throw an error getting deployments for chainId 999999', async () => {
try {
await getDeployments(999999)
} catch(error: any) {
if(error.message !== "There was a problem reading the deployment file for chainId '999999'") {
throw new Error("Unexpected error in test")
}
}
})
})
35 changes: 35 additions & 0 deletions src/deployments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {NetworkDeployment} from "./types/NetworkDeployment";

const NETWORK_PATH = "../networks/"

export function getDeployments(chainId: number): NetworkDeployment[] {
try{
return require(NETWORK_PATH + chainId + ".json")
} catch(error) {
throw new Error(`There was a problem reading the deployment file for chainId '${chainId}'`)
}
}

export function getRevocationRegistryDeployment(chainId: number): NetworkDeployment {
try{
const deployments = getDeployments(chainId)
if(typeof deployments === 'undefined' || deployments.length === 0) {
throw new Error(`No deployments found for chainId ${chainId}`)
}
const deployment = deployments.find(deployment => deployment.contractName === "RevocationRegistry")
if(typeof deployment === 'undefined') {
throw new Error(`No Revocation Registry deployment found for chainId ${chainId}`)
}
return deployment
} catch(error) {
throw new Error(`There was a problem reading the deployment file for chainId '${chainId}: ${error}'`)
}
}

export function getRevocationRegistryDeploymentAddress(chainId: number): string {
const registry = getRevocationRegistryDeployment(chainId)
if(typeof registry.address === 'undefined' || registry.address !== "") {
throw new Error("Contract address has not been found")
}
return registry.address
}
30 changes: 20 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
export {
EIP712DomainName,
EIP712ChangeStatusType,
EIP712ChangeStatusDelegatedType,
EIP712ChangeStatusesInListType,
EIP712ChangeStatusesInListDelegatedType,
EIP712ChangeListOwnerType,
EIP712AddListDelegateType,
EIP712RemoveListDelegateType,
EIP712ChangeListStatusType,
} from "./util"
EIP712DomainName,
EIP712ChangeStatusType,
EIP712ChangeStatusDelegatedType,
EIP712ChangeStatusesInListType,
EIP712ChangeStatusesInListDelegatedType,
EIP712ChangeListOwnerType,
EIP712AddListDelegateType,
EIP712RemoveListDelegateType,
EIP712ChangeListStatusType,
} from "./util"

export {
getDeployments,
getRevocationRegistryDeployment,
getRevocationRegistryDeploymentAddress
} from "./deployments"

export {
NetworkDeployment
} from "./types/NetworkDeployment"
5 changes: 5 additions & 0 deletions src/types/NetworkDeployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type NetworkDeployment = {
contractName: string
address: string
transactionHash: string
}

0 comments on commit 7d69cb4

Please sign in to comment.