Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[contractkit] 0.1 release + tests (#628)
* Fix test configuration * Test contract & wrapper caches * contrackit v0.1.0
- Loading branch information
Mariano Cortesi
committed
Aug 18, 2019
1 parent
1d8bee1
commit 7524b66
Showing
10 changed files
with
97 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
const { pathsToModuleNameMapper } = require('ts-jest/utils') | ||
|
||
const { compilerOptions } = require('./test/tsconfig') | ||
|
||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
moduleNameMapper: { | ||
'^src/(.*)$': '<rootDir>/src/$1', | ||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }), | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: '<rootDir>/test/tsconfig.json', | ||
}, | ||
}, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ValidWrappers, WrapperCache } from '@src/contract-cache' | ||
import { CeloContract, newKit } from '@src/index' | ||
|
||
const TestedWrappers: ValidWrappers[] = [ | ||
CeloContract.GoldToken, | ||
CeloContract.StableToken, | ||
CeloContract.Exchange, | ||
CeloContract.Validators, | ||
CeloContract.BondedDeposits, | ||
] | ||
|
||
function newWrapperCache() { | ||
const kit = newKit('') | ||
const AnyContractAddress = '0xe832065fb5117dbddcb566ff7dc4340999583e38' | ||
jest.spyOn(kit.registry, 'addressFor').mockResolvedValue(AnyContractAddress) | ||
const contractCache = new WrapperCache(kit) | ||
return contractCache | ||
} | ||
|
||
describe('getContract()', () => { | ||
const contractCache = newWrapperCache() | ||
|
||
for (const contractName of TestedWrappers) { | ||
test(`SBAT get ${contractName}`, async () => { | ||
const contract = await contractCache.getContract(contractName) | ||
expect(contract).not.toBeNull() | ||
expect(contract).toBeDefined() | ||
}) | ||
} | ||
}) | ||
|
||
test('should cache contracts', async () => { | ||
const contractCache = newWrapperCache() | ||
for (const contractName of TestedWrappers) { | ||
const contract = await contractCache.getContract(contractName) | ||
const contractBis = await contractCache.getContract(contractName) | ||
expect(contract).toBe(contractBis) | ||
} | ||
}) |
31 changes: 31 additions & 0 deletions
31
packages/contractkit/test/cache/web3-contract-cache.test.ts
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,31 @@ | ||
import { AllContracts, newKit } from '@src/index' | ||
import { Web3ContractCache } from '@src/web3-contract-cache' | ||
|
||
function newWeb3ContractCache() { | ||
const kit = newKit('') | ||
const AnyContractAddress = '0xe832065fb5117dbddcb566ff7dc4340999583e38' | ||
jest.spyOn(kit.registry, 'addressFor').mockResolvedValue(AnyContractAddress) | ||
const contractCache = new Web3ContractCache(kit) | ||
return contractCache | ||
} | ||
|
||
describe('getContract()', () => { | ||
const contractCache = newWeb3ContractCache() | ||
|
||
for (const contractName of AllContracts) { | ||
test(`SBAT get ${contractName}`, async () => { | ||
const contract = await contractCache.getContract(contractName) | ||
expect(contract).not.toBeNull() | ||
expect(contract).toBeDefined() | ||
}) | ||
} | ||
}) | ||
|
||
test('should cache contracts', async () => { | ||
const contractCache = newWeb3ContractCache() | ||
for (const contractName of AllContracts) { | ||
const contract = await contractCache.getContract(contractName) | ||
const contractBis = await contractCache.getContract(contractName) | ||
expect(contract).toBe(contractBis) | ||
} | ||
}) |
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