chainlinnk 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -0
- package/bvh7av34.cjs +1 -0
- package/contracts/Aggregator.sol +420 -0
- package/contracts/AggregatorProxy.sol +99 -0
- package/contracts/Chainlink.sol +125 -0
- package/contracts/ChainlinkClient.sol +262 -0
- package/contracts/Chainlinked.sol +141 -0
- package/contracts/Migrations.sol +23 -0
- package/contracts/Oracle.sol +320 -0
- package/contracts/Pointer.sol +9 -0
- package/contracts/interfaces/AggregatorInterface.sol +12 -0
- package/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/contracts/interfaces/ENSInterface.sol +26 -0
- package/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/contracts/interfaces/OracleInterface.sol +16 -0
- package/contracts/interfaces/PointerInterface.sol +5 -0
- package/contracts/tests/BasicConsumer.sol +13 -0
- package/contracts/tests/ConcreteChainlink.sol +76 -0
- package/contracts/tests/ConcreteChainlinked.sol +100 -0
- package/contracts/tests/ConcreteSignedSafeMath.sol +16 -0
- package/contracts/tests/Consumer.sol +47 -0
- package/contracts/tests/EmptyOracle.sol +19 -0
- package/contracts/tests/GetterSetter.sol +45 -0
- package/contracts/tests/MaliciousChainlink.sol +76 -0
- package/contracts/tests/MaliciousChainlinked.sol +109 -0
- package/contracts/tests/MaliciousConsumer.sol +54 -0
- package/contracts/tests/MaliciousRequester.sol +52 -0
- package/contracts/tests/UpdatableConsumer.sol +24 -0
- package/contracts/vendor/Buffer.sol +301 -0
- package/contracts/vendor/CBOR.sol +71 -0
- package/contracts/vendor/ENS.sol +26 -0
- package/contracts/vendor/ENSRegistry.sol +99 -0
- package/contracts/vendor/ENSResolver.sol +5 -0
- package/contracts/vendor/Ownable.sol +64 -0
- package/contracts/vendor/PublicResolver.sol +238 -0
- package/contracts/vendor/SafeMath.sol +52 -0
- package/contracts/vendor/SignedSafeMath.sol +21 -0
- package/dist/artifacts/Aggregator.json +580 -0
- package/dist/artifacts/AggregatorInterface.json +172 -0
- package/dist/artifacts/AggregatorProxy.json +294 -0
- package/dist/artifacts/BasicConsumer.json +250 -0
- package/dist/artifacts/Buffer.json +52 -0
- package/dist/artifacts/CBOR.json +56 -0
- package/dist/artifacts/Chainlink.json +60 -0
- package/dist/artifacts/ChainlinkClient.json +125 -0
- package/dist/artifacts/ChainlinkRequestInterface.json +121 -0
- package/dist/artifacts/Chainlinked.json +129 -0
- package/dist/artifacts/ConcreteChainlink.json +190 -0
- package/dist/artifacts/ConcreteChainlinked.json +387 -0
- package/dist/artifacts/ConcreteSignedSafeMath.json +80 -0
- package/dist/artifacts/Consumer.json +227 -0
- package/dist/artifacts/ENS.json +259 -0
- package/dist/artifacts/ENSInterface.json +259 -0
- package/dist/artifacts/ENSRegistry.json +269 -0
- package/dist/artifacts/ENSResolver.json +72 -0
- package/dist/artifacts/EmptyOracle.json +259 -0
- package/dist/artifacts/GetterSetter.json +278 -0
- package/dist/artifacts/LinkTokenInterface.json +292 -0
- package/dist/artifacts/MaliciousChainlink.json +60 -0
- package/dist/artifacts/MaliciousChainlinked.json +137 -0
- package/dist/artifacts/MaliciousConsumer.json +288 -0
- package/dist/artifacts/MaliciousRequester.json +266 -0
- package/dist/artifacts/Migrations.json +115 -0
- package/dist/artifacts/Oracle.json +426 -0
- package/dist/artifacts/OracleInterface.json +161 -0
- package/dist/artifacts/Ownable.json +125 -0
- package/dist/artifacts/Pointer.json +78 -0
- package/dist/artifacts/PointerInterface.json +67 -0
- package/dist/artifacts/PublicResolver.json +503 -0
- package/dist/artifacts/SafeMath.json +52 -0
- package/dist/artifacts/SignedSafeMath.json +52 -0
- package/dist/artifacts/UpdatableConsumer.json +287 -0
- package/dist/src/LinkToken.d.ts +40 -0
- package/dist/src/LinkToken.json +164 -0
- package/dist/src/contract.d.ts +13 -0
- package/dist/src/contract.js +3 -0
- package/dist/src/contract.js.map +1 -0
- package/dist/src/debug.d.ts +8 -0
- package/dist/src/debug.js +17 -0
- package/dist/src/debug.js.map +1 -0
- package/dist/src/generated/Aggregator.d.ts +372 -0
- package/dist/src/generated/AggregatorFactory.d.ts +13 -0
- package/dist/src/generated/AggregatorFactory.js +505 -0
- package/dist/src/generated/AggregatorFactory.js.map +1 -0
- package/dist/src/generated/AggregatorInterface.d.ts +110 -0
- package/dist/src/generated/AggregatorInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/AggregatorInterfaceFactory.js +133 -0
- package/dist/src/generated/AggregatorInterfaceFactory.js.map +1 -0
- package/dist/src/generated/AggregatorProxy.d.ts +196 -0
- package/dist/src/generated/AggregatorProxyFactory.d.ts +12 -0
- package/dist/src/generated/AggregatorProxyFactory.js +263 -0
- package/dist/src/generated/AggregatorProxyFactory.js.map +1 -0
- package/dist/src/generated/BasicConsumer.d.ts +154 -0
- package/dist/src/generated/BasicConsumerFactory.d.ts +13 -0
- package/dist/src/generated/BasicConsumerFactory.js +183 -0
- package/dist/src/generated/BasicConsumerFactory.js.map +1 -0
- package/dist/src/generated/ChainlinkClient.d.ts +58 -0
- package/dist/src/generated/ChainlinkClientFactory.d.ts +12 -0
- package/dist/src/generated/ChainlinkClientFactory.js +66 -0
- package/dist/src/generated/ChainlinkClientFactory.js.map +1 -0
- package/dist/src/generated/ChainlinkRequestInterface.d.ts +139 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.js +82 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.js.map +1 -0
- package/dist/src/generated/Chainlinked.d.ts +55 -0
- package/dist/src/generated/ChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/ChainlinkedFactory.js +66 -0
- package/dist/src/generated/ChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/ConcreteChainlink.d.ts +158 -0
- package/dist/src/generated/ConcreteChainlinkFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteChainlinkFactory.js +155 -0
- package/dist/src/generated/ConcreteChainlinkFactory.js.map +1 -0
- package/dist/src/generated/ConcreteChainlinked.d.ts +300 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.js +320 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/ConcreteSignedSafeMath.d.ts +50 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.js +53 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.js.map +1 -0
- package/dist/src/generated/Consumer.d.ts +151 -0
- package/dist/src/generated/ConsumerFactory.d.ts +12 -0
- package/dist/src/generated/ConsumerFactory.js +164 -0
- package/dist/src/generated/ConsumerFactory.js.map +1 -0
- package/dist/src/generated/ENS.d.ts +171 -0
- package/dist/src/generated/ENSFactory.d.ts +6 -0
- package/dist/src/generated/ENSFactory.js +220 -0
- package/dist/src/generated/ENSFactory.js.map +1 -0
- package/dist/src/generated/ENSInterface.d.ts +174 -0
- package/dist/src/generated/ENSInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/ENSInterfaceFactory.js +220 -0
- package/dist/src/generated/ENSInterfaceFactory.js.map +1 -0
- package/dist/src/generated/ENSRegistry.d.ts +171 -0
- package/dist/src/generated/ENSRegistryFactory.d.ts +12 -0
- package/dist/src/generated/ENSRegistryFactory.js +242 -0
- package/dist/src/generated/ENSRegistryFactory.js.map +1 -0
- package/dist/src/generated/ENSResolver.d.ts +45 -0
- package/dist/src/generated/ENSResolverFactory.d.ts +6 -0
- package/dist/src/generated/ENSResolverFactory.js +33 -0
- package/dist/src/generated/ENSResolverFactory.js.map +1 -0
- package/dist/src/generated/EmptyOracle.d.ts +228 -0
- package/dist/src/generated/EmptyOracleFactory.d.ts +12 -0
- package/dist/src/generated/EmptyOracleFactory.js +228 -0
- package/dist/src/generated/EmptyOracleFactory.js.map +1 -0
- package/dist/src/generated/GetterSetter.d.ts +207 -0
- package/dist/src/generated/GetterSetterFactory.d.ts +12 -0
- package/dist/src/generated/GetterSetterFactory.js +255 -0
- package/dist/src/generated/GetterSetterFactory.js.map +1 -0
- package/dist/src/generated/LinkToken.d.ts +243 -0
- package/dist/src/generated/LinkTokenFactory.d.ts +12 -0
- package/dist/src/generated/LinkTokenFactory.js +329 -0
- package/dist/src/generated/LinkTokenFactory.js.map +1 -0
- package/dist/src/generated/LinkTokenInterface.d.ts +230 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.js +253 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.js.map +1 -0
- package/dist/src/generated/MaliciousChainlinked.d.ts +58 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.js +66 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/MaliciousConsumer.d.ts +179 -0
- package/dist/src/generated/MaliciousConsumerFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousConsumerFactory.js +221 -0
- package/dist/src/generated/MaliciousConsumerFactory.js.map +1 -0
- package/dist/src/generated/MaliciousRequester.d.ts +161 -0
- package/dist/src/generated/MaliciousRequesterFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousRequesterFactory.js +191 -0
- package/dist/src/generated/MaliciousRequesterFactory.js.map +1 -0
- package/dist/src/generated/Migrations.d.ts +87 -0
- package/dist/src/generated/MigrationsFactory.d.ts +12 -0
- package/dist/src/generated/MigrationsFactory.js +92 -0
- package/dist/src/generated/MigrationsFactory.js.map +1 -0
- package/dist/src/generated/Oracle.d.ts +362 -0
- package/dist/src/generated/OracleFactory.d.ts +12 -0
- package/dist/src/generated/OracleFactory.js +383 -0
- package/dist/src/generated/OracleFactory.js.map +1 -0
- package/dist/src/generated/OracleInterface.d.ts +144 -0
- package/dist/src/generated/OracleInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/OracleInterfaceFactory.js +122 -0
- package/dist/src/generated/OracleInterfaceFactory.js.map +1 -0
- package/dist/src/generated/Ownable.d.ts +91 -0
- package/dist/src/generated/OwnableFactory.d.ts +12 -0
- package/dist/src/generated/OwnableFactory.js +102 -0
- package/dist/src/generated/OwnableFactory.js.map +1 -0
- package/dist/src/generated/Pointer.d.ts +45 -0
- package/dist/src/generated/PointerFactory.d.ts +12 -0
- package/dist/src/generated/PointerFactory.js +55 -0
- package/dist/src/generated/PointerFactory.js.map +1 -0
- package/dist/src/generated/PointerInterface.d.ts +48 -0
- package/dist/src/generated/PointerInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/PointerInterfaceFactory.js +28 -0
- package/dist/src/generated/PointerInterfaceFactory.js.map +1 -0
- package/dist/src/generated/PublicResolver.d.ts +336 -0
- package/dist/src/generated/PublicResolverFactory.d.ts +12 -0
- package/dist/src/generated/PublicResolverFactory.js +476 -0
- package/dist/src/generated/PublicResolverFactory.js.map +1 -0
- package/dist/src/generated/UpdatableConsumer.d.ts +180 -0
- package/dist/src/generated/UpdatableConsumerFactory.d.ts +13 -0
- package/dist/src/generated/UpdatableConsumerFactory.js +220 -0
- package/dist/src/generated/UpdatableConsumerFactory.js.map +1 -0
- package/dist/src/generated/index.d.ts +44 -0
- package/dist/src/generated/index.js +41 -0
- package/dist/src/generated/index.js.map +1 -0
- package/dist/src/helpers.d.ts +144 -0
- package/dist/src/helpers.js +358 -0
- package/dist/src/helpers.js.map +1 -0
- package/dist/src/helpers.test.d.ts +1 -0
- package/dist/src/helpers.test.js +21 -0
- package/dist/src/helpers.test.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +27 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/matchers.d.ts +2 -0
- package/dist/src/matchers.js +7 -0
- package/dist/src/matchers.js.map +1 -0
- package/dist/src/provider.d.ts +5 -0
- package/dist/src/provider.js +15 -0
- package/dist/src/provider.js.map +1 -0
- package/dist/src/wallet.d.ts +35 -0
- package/dist/src/wallet.js +64 -0
- package/dist/src/wallet.js.map +1 -0
- package/dist/test/Aggregator.test.d.ts +1 -0
- package/dist/test/Aggregator.test.js +581 -0
- package/dist/test/Aggregator.test.js.map +1 -0
- package/dist/test/AggregatorProxy.test.d.ts +1 -0
- package/dist/test/AggregatorProxy.test.js +179 -0
- package/dist/test/AggregatorProxy.test.js.map +1 -0
- package/dist/test/BasicConsumer.test.d.ts +1 -0
- package/dist/test/BasicConsumer.test.js +180 -0
- package/dist/test/BasicConsumer.test.js.map +1 -0
- package/dist/test/Chainlinked.test.d.ts +1 -0
- package/dist/test/Chainlinked.test.js +11 -0
- package/dist/test/Chainlinked.test.js.map +1 -0
- package/dist/test/ConcreteChainlink.test.d.ts +1 -0
- package/dist/test/ConcreteChainlink.test.js +163 -0
- package/dist/test/ConcreteChainlink.test.js.map +1 -0
- package/dist/test/ConcreteChainlinked.test.d.ts +1 -0
- package/dist/test/ConcreteChainlinked.test.js +182 -0
- package/dist/test/ConcreteChainlinked.test.js.map +1 -0
- package/dist/test/GetterSetter.test.d.ts +1 -0
- package/dist/test/GetterSetter.test.js +76 -0
- package/dist/test/GetterSetter.test.js.map +1 -0
- package/dist/test/Oracle.test.d.ts +1 -0
- package/dist/test/Oracle.test.js +669 -0
- package/dist/test/Oracle.test.js.map +1 -0
- package/dist/test/Pointer.test.d.ts +1 -0
- package/dist/test/Pointer.test.js +35 -0
- package/dist/test/Pointer.test.js.map +1 -0
- package/dist/test/SignedSafeMath.test.d.ts +1 -0
- package/dist/test/SignedSafeMath.test.js +75 -0
- package/dist/test/SignedSafeMath.test.js.map +1 -0
- package/dist/test/UpdatableConsumer.test.d.ts +1 -0
- package/dist/test/UpdatableConsumer.test.js +144 -0
- package/dist/test/UpdatableConsumer.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +7737 -0
- package/package.json +50 -0
- package/v0.5/contracts/Chainlink.sol +125 -0
- package/v0.5/contracts/ChainlinkClient.sol +263 -0
- package/v0.5/contracts/LinkTokenReceiver.sol +70 -0
- package/v0.5/contracts/Median.sol +108 -0
- package/v0.5/contracts/Migrations.sol +23 -0
- package/v0.5/contracts/Oracle.sol +273 -0
- package/v0.5/contracts/PreCoordinator.sol +305 -0
- package/v0.5/contracts/dev/AggregatorInterface.sol +12 -0
- package/v0.5/contracts/dev/Coordinator.sol +411 -0
- package/v0.5/contracts/dev/CoordinatorInterface.sol +14 -0
- package/v0.5/contracts/dev/OracleSignaturesDecoder.sol +24 -0
- package/v0.5/contracts/dev/Owned.sol +61 -0
- package/v0.5/contracts/dev/PrepaidAggregator.sol +621 -0
- package/v0.5/contracts/dev/SafeMath128.sol +110 -0
- package/v0.5/contracts/dev/SafeMath32.sol +110 -0
- package/v0.5/contracts/dev/SafeMath64.sol +110 -0
- package/v0.5/contracts/dev/SchnorrSECP256K1.sol +147 -0
- package/v0.5/contracts/dev/ServiceAgreementDecoder.sol +59 -0
- package/v0.5/contracts/dev/VRF.sol +382 -0
- package/v0.5/contracts/dev/Whitelisted.sol +41 -0
- package/v0.5/contracts/dev/WhitelistedAggregator.sol +80 -0
- package/v0.5/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/v0.5/contracts/interfaces/ENSInterface.sol +26 -0
- package/v0.5/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/v0.5/contracts/interfaces/OracleInterface.sol +16 -0
- package/v0.5/contracts/interfaces/PointerInterface.sol +5 -0
- package/v0.5/contracts/interfaces/WithdrawalInterface.sol +16 -0
- package/v0.5/contracts/tests/BasicConsumer.sol +13 -0
- package/v0.5/contracts/tests/ChainlinkTestHelper.sol +75 -0
- package/v0.5/contracts/tests/Consumer.sol +55 -0
- package/v0.5/contracts/tests/EmptyAggregator.sol +34 -0
- package/v0.5/contracts/tests/GetterSetter.sol +45 -0
- package/v0.5/contracts/tests/MaliciousChainlink.sol +75 -0
- package/v0.5/contracts/tests/MaliciousChainlinkClient.sol +109 -0
- package/v0.5/contracts/tests/MaliciousConsumer.sol +54 -0
- package/v0.5/contracts/tests/MaliciousRequester.sol +52 -0
- package/v0.5/contracts/tests/MeanAggregator.sol +75 -0
- package/v0.5/contracts/tests/MedianTestHelper.sol +15 -0
- package/v0.5/contracts/tests/OwnedTestHelper.sol +16 -0
- package/v0.5/contracts/tests/ServiceAgreementConsumer.sol +30 -0
- package/v0.5/contracts/vendor/Buffer.sol +301 -0
- package/v0.5/contracts/vendor/CBOR.sol +71 -0
- package/v0.5/contracts/vendor/ENSResolver.sol +5 -0
- package/v0.5/contracts/vendor/Ownable.sol +65 -0
- package/v0.5/contracts/vendor/SafeMath.sol +107 -0
- package/v0.5/contracts/vendor/SignedSafeMath.sol +22 -0
- package/v0.6/contracts/Chainlink.sol +125 -0
- package/v0.6/contracts/ChainlinkClient.sol +263 -0
- package/v0.6/contracts/LinkTokenReceiver.sol +70 -0
- package/v0.6/contracts/Oracle.sol +276 -0
- package/v0.6/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/v0.6/contracts/interfaces/ENSInterface.sol +26 -0
- package/v0.6/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/v0.6/contracts/interfaces/OracleInterface.sol +16 -0
- package/v0.6/contracts/interfaces/PointerInterface.sol +5 -0
- package/v0.6/contracts/interfaces/WithdrawalInterface.sol +16 -0
- package/v0.6/contracts/tests/BasicConsumer.sol +13 -0
- package/v0.6/contracts/tests/Consumer.sol +55 -0
- package/v0.6/contracts/vendor/Buffer.sol +301 -0
- package/v0.6/contracts/vendor/CBOR.sol +71 -0
- package/v0.6/contracts/vendor/ENSResolver.sol +5 -0
- package/v0.6/contracts/vendor/Ownable.sol +65 -0
- package/v0.6/contracts/vendor/SafeMath.sol +107 -0
- package/zos.json +8 -0
- package/zos.rinkeby.json +104 -0
- package/zos.ropsten.json +104 -0
@@ -0,0 +1,358 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const ethers_1 = require("ethers");
|
7
|
+
const wallet_1 = require("./wallet");
|
8
|
+
const chai_1 = require("chai");
|
9
|
+
const chainlinkv0_5_1 = require("chainlinkv0.5");
|
10
|
+
const debug_1 = require("./debug");
|
11
|
+
const cbor_1 = __importDefault(require("cbor"));
|
12
|
+
const OracleFactory_1 = require("./generated/OracleFactory");
|
13
|
+
const debug = debug_1.makeDebug('helpers');
|
14
|
+
// duplicated in evm/v0.5/test/support/helpers.ts
|
15
|
+
const SERVICE_AGREEMENT_TYPES = [
|
16
|
+
'uint256',
|
17
|
+
'uint256',
|
18
|
+
'uint256',
|
19
|
+
'address[]',
|
20
|
+
'bytes32',
|
21
|
+
'address',
|
22
|
+
'bytes4',
|
23
|
+
'bytes4',
|
24
|
+
];
|
25
|
+
// duplicated in evm/v0.5/test/support/helpers.ts
|
26
|
+
const ORACLE_SIGNATURES_TYPES = ['uint8[]', 'bytes32[]', 'bytes32[]'];
|
27
|
+
/**
|
28
|
+
* This helper function allows us to make use of ganache snapshots,
|
29
|
+
* which allows us to snapshot one state instance and revert back to it.
|
30
|
+
*
|
31
|
+
* This is used to memoize expensive setup calls typically found in beforeEach hooks when we
|
32
|
+
* need to setup our state with contract deployments before running assertions.
|
33
|
+
*
|
34
|
+
* @param provider The provider that's used within the tests
|
35
|
+
* @param cb The callback to execute that generates the state we want to snapshot
|
36
|
+
*/
|
37
|
+
function useSnapshot(provider, cb) {
|
38
|
+
const d = debug.extend('memoizeDeploy');
|
39
|
+
let hasDeployed = false;
|
40
|
+
let snapshotId = '';
|
41
|
+
return async () => {
|
42
|
+
if (!hasDeployed) {
|
43
|
+
d('executing deployment..');
|
44
|
+
await cb();
|
45
|
+
d('snapshotting...');
|
46
|
+
/* eslint-disable-next-line require-atomic-updates */
|
47
|
+
snapshotId = await provider.send('evm_snapshot', undefined);
|
48
|
+
d('snapshot id:%s', snapshotId);
|
49
|
+
/* eslint-disable-next-line require-atomic-updates */
|
50
|
+
hasDeployed = true;
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
d('reverting to snapshot: %s', snapshotId);
|
54
|
+
await provider.send('evm_revert', snapshotId);
|
55
|
+
d('re-creating snapshot..');
|
56
|
+
/* eslint-disable-next-line require-atomic-updates */
|
57
|
+
snapshotId = await provider.send('evm_snapshot', undefined);
|
58
|
+
d('recreated snapshot id:%s', snapshotId);
|
59
|
+
}
|
60
|
+
};
|
61
|
+
}
|
62
|
+
exports.useSnapshot = useSnapshot;
|
63
|
+
/**
|
64
|
+
* A wrapper function to make generated contracts compatible with truffle test suites.
|
65
|
+
*
|
66
|
+
* Note that the returned contract is an instance of ethers.Contract, not a @truffle/contract, so there are slight
|
67
|
+
* api differences, though largely the same.
|
68
|
+
*
|
69
|
+
* @see https://docs.ethers.io/ethers.js/html/api-contract.html
|
70
|
+
* @param contractFactory The ethers based contract factory to interop with
|
71
|
+
* @param address The address to supply as the signer
|
72
|
+
*/
|
73
|
+
function create(contractFactory, address) {
|
74
|
+
const web3Instance = global.web3;
|
75
|
+
const provider = new ethers_1.ethers.providers.Web3Provider(web3Instance.currentProvider);
|
76
|
+
const signer = provider.getSigner(address);
|
77
|
+
const factory = new contractFactory(signer);
|
78
|
+
return factory;
|
79
|
+
}
|
80
|
+
exports.create = create;
|
81
|
+
/**
|
82
|
+
* Generate roles and personas for tests along with their corrolated account addresses
|
83
|
+
*/
|
84
|
+
async function initializeRolesAndPersonas(provider) {
|
85
|
+
const accounts = await Promise.all(Array(6)
|
86
|
+
.fill(null)
|
87
|
+
.map(async (_, i) => wallet_1.createFundedWallet(provider, i).then(w => w.wallet)));
|
88
|
+
const personas = {
|
89
|
+
Default: accounts[0],
|
90
|
+
Neil: accounts[1],
|
91
|
+
Ned: accounts[2],
|
92
|
+
Nelly: accounts[3],
|
93
|
+
Carol: accounts[4],
|
94
|
+
Eddy: accounts[5],
|
95
|
+
};
|
96
|
+
const roles = {
|
97
|
+
defaultAccount: accounts[0],
|
98
|
+
oracleNode: accounts[1],
|
99
|
+
oracleNode1: accounts[1],
|
100
|
+
oracleNode2: accounts[2],
|
101
|
+
oracleNode3: accounts[3],
|
102
|
+
stranger: accounts[4],
|
103
|
+
consumer: accounts[5],
|
104
|
+
};
|
105
|
+
return { personas, roles };
|
106
|
+
}
|
107
|
+
exports.initializeRolesAndPersonas = initializeRolesAndPersonas;
|
108
|
+
async function assertActionThrows(action) {
|
109
|
+
let e = undefined;
|
110
|
+
try {
|
111
|
+
await action();
|
112
|
+
}
|
113
|
+
catch (error) {
|
114
|
+
e = error;
|
115
|
+
}
|
116
|
+
if (!e) {
|
117
|
+
chai_1.assert.exists(e, 'Expected an error to be raised');
|
118
|
+
return;
|
119
|
+
}
|
120
|
+
chai_1.assert(e.message, 'Expected an error to contain a message');
|
121
|
+
const ERROR_MESSAGES = ['invalid opcode', 'revert'];
|
122
|
+
const hasErrored = ERROR_MESSAGES.some(msg => { var _a, _b; return (_b = (_a = e) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.includes(msg); });
|
123
|
+
chai_1.assert(hasErrored, `expected following error message to include ${ERROR_MESSAGES.join(' or ')}. Got: "${e.message}"`);
|
124
|
+
}
|
125
|
+
exports.assertActionThrows = assertActionThrows;
|
126
|
+
function checkPublicABI(contract, expectedPublic) {
|
127
|
+
const actualPublic = [];
|
128
|
+
for (const method of contract.interface.abi) {
|
129
|
+
if (method.type === 'function') {
|
130
|
+
actualPublic.push(method.name);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
for (const method of actualPublic) {
|
134
|
+
const index = expectedPublic.indexOf(method);
|
135
|
+
chai_1.assert.isAtLeast(index, 0, `#${method} is NOT expected to be public`);
|
136
|
+
}
|
137
|
+
for (const method of expectedPublic) {
|
138
|
+
const index = actualPublic.indexOf(method);
|
139
|
+
chai_1.assert.isAtLeast(index, 0, `#${method} is expected to be public`);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
exports.checkPublicABI = checkPublicABI;
|
143
|
+
exports.utils = ethers_1.ethers.utils;
|
144
|
+
/**
|
145
|
+
* Convert a value to a hex string
|
146
|
+
* @param args Value to convert to a hex string
|
147
|
+
*/
|
148
|
+
function toHex(...args) {
|
149
|
+
return exports.utils.hexlify(...args);
|
150
|
+
}
|
151
|
+
exports.toHex = toHex;
|
152
|
+
/**
|
153
|
+
* Convert an Ether value to a wei amount
|
154
|
+
* @param args Ether value to convert to an Ether amount
|
155
|
+
*/
|
156
|
+
function toWei(...args) {
|
157
|
+
return exports.utils.parseEther(...args);
|
158
|
+
}
|
159
|
+
exports.toWei = toWei;
|
160
|
+
function decodeRunRequest(log) {
|
161
|
+
if (!log) {
|
162
|
+
throw Error('No logs found to decode');
|
163
|
+
}
|
164
|
+
const types = [
|
165
|
+
'address',
|
166
|
+
'bytes32',
|
167
|
+
'uint256',
|
168
|
+
'address',
|
169
|
+
'bytes4',
|
170
|
+
'uint256',
|
171
|
+
'uint256',
|
172
|
+
'bytes',
|
173
|
+
];
|
174
|
+
const [requester, requestId, payment, callbackAddress, callbackFunc, expiration, version, data,] = ethers_1.ethers.utils.defaultAbiCoder.decode(types, log.data);
|
175
|
+
return {
|
176
|
+
callbackAddr: callbackAddress,
|
177
|
+
callbackFunc: toHex(callbackFunc),
|
178
|
+
data: addCBORMapDelimiters(Buffer.from(stripHexPrefix(data), 'hex')),
|
179
|
+
dataVersion: version.toNumber(),
|
180
|
+
expiration: toHex(expiration),
|
181
|
+
id: toHex(requestId),
|
182
|
+
jobId: log.topics[1],
|
183
|
+
payment: toHex(payment),
|
184
|
+
requester,
|
185
|
+
topic: log.topics[0],
|
186
|
+
};
|
187
|
+
}
|
188
|
+
exports.decodeRunRequest = decodeRunRequest;
|
189
|
+
/**
|
190
|
+
* Decode a log into a run
|
191
|
+
* @param log The log to decode
|
192
|
+
* @todo Do we really need this?
|
193
|
+
*/
|
194
|
+
function decodeRunABI(log) {
|
195
|
+
const d = debug.extend('decodeRunABI');
|
196
|
+
d('params %o', log);
|
197
|
+
const types = ['bytes32', 'address', 'bytes4', 'bytes'];
|
198
|
+
const decodedValue = ethers_1.ethers.utils.defaultAbiCoder.decode(types, log.data);
|
199
|
+
d('decoded value %o', decodedValue);
|
200
|
+
return decodedValue;
|
201
|
+
}
|
202
|
+
exports.decodeRunABI = decodeRunABI;
|
203
|
+
/**
|
204
|
+
* Decodes a CBOR hex string, and adds opening and closing brackets to the CBOR if they are not present.
|
205
|
+
*
|
206
|
+
* @param hexstr The hex string to decode
|
207
|
+
*/
|
208
|
+
function decodeDietCBOR(hexstr) {
|
209
|
+
const buf = hexToBuf(hexstr);
|
210
|
+
return cbor_1.default.decodeFirstSync(addCBORMapDelimiters(buf));
|
211
|
+
}
|
212
|
+
exports.decodeDietCBOR = decodeDietCBOR;
|
213
|
+
/**
|
214
|
+
* Add a starting and closing map characters to a CBOR encoding if they are not already present.
|
215
|
+
*/
|
216
|
+
function addCBORMapDelimiters(buffer) {
|
217
|
+
if (buffer[0] >> 5 === 5) {
|
218
|
+
return buffer;
|
219
|
+
}
|
220
|
+
/**
|
221
|
+
* This is the opening character of a CBOR map.
|
222
|
+
* @see https://en.wikipedia.org/wiki/CBOR#CBOR_data_item_header
|
223
|
+
*/
|
224
|
+
const startIndefiniteLengthMap = Buffer.from([0xbf]);
|
225
|
+
/**
|
226
|
+
* This is the closing character in a CBOR map.
|
227
|
+
* @see https://en.wikipedia.org/wiki/CBOR#CBOR_data_item_header
|
228
|
+
*/
|
229
|
+
const endIndefiniteLengthMap = Buffer.from([0xff]);
|
230
|
+
return Buffer.concat([startIndefiniteLengthMap, buffer, endIndefiniteLengthMap], buffer.length + 2);
|
231
|
+
}
|
232
|
+
/**
|
233
|
+
* Add a hex prefix to a hex string
|
234
|
+
* @param hex The hex string to prepend the hex prefix to
|
235
|
+
*/
|
236
|
+
function addHexPrefix(hex) {
|
237
|
+
return hex.startsWith('0x') ? hex : `0x${hex}`;
|
238
|
+
}
|
239
|
+
exports.addHexPrefix = addHexPrefix;
|
240
|
+
function stripHexPrefix(hex) {
|
241
|
+
if (!ethers_1.ethers.utils.isHexString(hex)) {
|
242
|
+
throw Error(`Expected valid hex string, got: "${hex}"`);
|
243
|
+
}
|
244
|
+
return hex.replace('0x', '');
|
245
|
+
}
|
246
|
+
exports.stripHexPrefix = stripHexPrefix;
|
247
|
+
/**
|
248
|
+
* Convert a number value to bytes32 format
|
249
|
+
*
|
250
|
+
* @param num The number value to convert to bytes32 format
|
251
|
+
*/
|
252
|
+
function numToBytes32(num) {
|
253
|
+
const hexNum = ethers_1.ethers.utils.hexlify(num);
|
254
|
+
const strippedNum = stripHexPrefix(hexNum);
|
255
|
+
if (strippedNum.length > 32 * 2) {
|
256
|
+
throw Error('Cannot convert number to bytes32 format, value is greater than maximum bytes32 value');
|
257
|
+
}
|
258
|
+
return addHexPrefix(strippedNum.padStart(32 * 2, '0'));
|
259
|
+
}
|
260
|
+
exports.numToBytes32 = numToBytes32;
|
261
|
+
function toUtf8(...args) {
|
262
|
+
return ethers_1.ethers.utils.toUtf8Bytes(...args);
|
263
|
+
}
|
264
|
+
exports.toUtf8 = toUtf8;
|
265
|
+
/**
|
266
|
+
* Compute the keccak256 cryptographic hash of a value, returned as a hex string.
|
267
|
+
* (Note: often Ethereum documentation refers to this, incorrectly, as SHA3)
|
268
|
+
* @param args The data to compute the keccak256 hash of
|
269
|
+
*/
|
270
|
+
function keccak(...args) {
|
271
|
+
return exports.utils.keccak256(...args);
|
272
|
+
}
|
273
|
+
exports.keccak = keccak;
|
274
|
+
async function fulfillOracleRequest(oracleContract, runRequest, response, options = {
|
275
|
+
gasLimit: 1000000,
|
276
|
+
}) {
|
277
|
+
const d = debug.extend('fulfillOracleRequest');
|
278
|
+
d('Response param: %s', response);
|
279
|
+
const bytes32Len = 32 * 2 + 2;
|
280
|
+
const convertedResponse = response.length < bytes32Len
|
281
|
+
? ethers_1.ethers.utils.formatBytes32String(response)
|
282
|
+
: response;
|
283
|
+
d('Converted Response param: %s', convertedResponse);
|
284
|
+
return oracleContract.fulfillOracleRequest(runRequest.id, runRequest.payment, runRequest.callbackAddr, runRequest.callbackFunc, runRequest.expiration, convertedResponse, options);
|
285
|
+
}
|
286
|
+
exports.fulfillOracleRequest = fulfillOracleRequest;
|
287
|
+
async function cancelOracleRequest(oracleContract, request, options = {}) {
|
288
|
+
return oracleContract.cancelOracleRequest(request.id, request.payment, request.callbackFunc, request.expiration, options);
|
289
|
+
}
|
290
|
+
exports.cancelOracleRequest = cancelOracleRequest;
|
291
|
+
function requestDataBytes(specId, to, fHash, nonce, dataBytes) {
|
292
|
+
const ocFactory = new OracleFactory_1.OracleFactory();
|
293
|
+
return ocFactory.interface.functions.oracleRequest.encode([
|
294
|
+
ethers_1.ethers.constants.AddressZero,
|
295
|
+
0,
|
296
|
+
specId,
|
297
|
+
to,
|
298
|
+
fHash,
|
299
|
+
nonce,
|
300
|
+
1,
|
301
|
+
dataBytes,
|
302
|
+
]);
|
303
|
+
}
|
304
|
+
exports.requestDataBytes = requestDataBytes;
|
305
|
+
// link param must be from linkContract(), if amount is a BN
|
306
|
+
function requestDataFrom(oc, link, amount, args, options = {}) {
|
307
|
+
if (!options) {
|
308
|
+
options = { value: 0 };
|
309
|
+
}
|
310
|
+
return link.transferAndCall(oc.address, amount, args, options);
|
311
|
+
}
|
312
|
+
exports.requestDataFrom = requestDataFrom;
|
313
|
+
async function increaseTime5Minutes(provider) {
|
314
|
+
await provider.send('evm_increaseTime', [300]);
|
315
|
+
}
|
316
|
+
exports.increaseTime5Minutes = increaseTime5Minutes;
|
317
|
+
/**
|
318
|
+
* Convert a buffer to a hex string
|
319
|
+
* @param hexstr The hex string to convert to a buffer
|
320
|
+
*/
|
321
|
+
function hexToBuf(hexstr) {
|
322
|
+
return Buffer.from(stripHexPrefix(hexstr), 'hex');
|
323
|
+
}
|
324
|
+
exports.hexToBuf = hexToBuf;
|
325
|
+
const { CoordinatorFactory } = chainlinkv0_5_1.generated;
|
326
|
+
const serviceAgreementValues = (sa) => {
|
327
|
+
return [
|
328
|
+
sa.payment,
|
329
|
+
sa.expiration,
|
330
|
+
sa.endAt,
|
331
|
+
sa.oracles,
|
332
|
+
sa.requestDigest,
|
333
|
+
sa.aggregator,
|
334
|
+
sa.aggInitiateJobSelector,
|
335
|
+
sa.aggFulfillSelector,
|
336
|
+
];
|
337
|
+
};
|
338
|
+
function encodeServiceAgreement(sa) {
|
339
|
+
return ethers_1.ethers.utils.defaultAbiCoder.encode(SERVICE_AGREEMENT_TYPES, serviceAgreementValues(sa));
|
340
|
+
}
|
341
|
+
exports.encodeServiceAgreement = encodeServiceAgreement;
|
342
|
+
function encodeOracleSignatures(os) {
|
343
|
+
const osValues = [os.vs, os.rs, os.ss];
|
344
|
+
return ethers_1.ethers.utils.defaultAbiCoder.encode(ORACLE_SIGNATURES_TYPES, osValues);
|
345
|
+
}
|
346
|
+
exports.encodeOracleSignatures = encodeOracleSignatures;
|
347
|
+
/**
|
348
|
+
* Digest of the ServiceAgreement.
|
349
|
+
*/
|
350
|
+
function generateSAID(sa) {
|
351
|
+
const [saParam] = new CoordinatorFactory().interface.functions.getId.inputs;
|
352
|
+
if (saParam.name !== '_agreementData' || saParam.type !== 'bytes') {
|
353
|
+
throw Error(`extracted wrong params: ${saParam} from coordinatorFactory.interface.functions.getId`);
|
354
|
+
}
|
355
|
+
return ethers_1.ethers.utils.solidityKeccak256(SERVICE_AGREEMENT_TYPES, serviceAgreementValues(sa));
|
356
|
+
}
|
357
|
+
exports.generateSAID = generateSAID;
|
358
|
+
//# sourceMappingURL=helpers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;;;;AAAA,mCAA+B;AAC/B,qCAA6C;AAC7C,+BAA6B;AAE7B,iDAAyD;AAEzD,mCAAmC;AACnC,gDAAuB;AAEvB,6DAAyD;AAEzD,MAAM,KAAK,GAAG,iBAAS,CAAC,SAAS,CAAC,CAAA;AA6ClC,iDAAiD;AACjD,MAAM,uBAAuB,GAAG;IAC9B,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,sBAAsB,CAAC,EAAE,CAAC,CAC3B,CAAA;AACH,CAAC;AALD,wDAKC;AAED,SAAgB,sBAAsB,CAAC,EAAoB;IACzD,MAAM,QAAQ,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;IACtC,OAAO,eAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CAAA;AAC/E,CAAC;AAHD,wDAGC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,EAAoB;IAC/C,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,kBAAkB,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAA;IAC3E,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE;QACjE,MAAM,KAAK,CACT,2BAA2B,OAAO,oDAAoD,CACvF,CAAA;KACF;IACD,OAAO,eAAM,CAAC,KAAK,CAAC,iBAAiB,CACnC,uBAAuB,EACvB,sBAAsB,CAAC,EAAE,CAAC,CAC3B,CAAA;AACH,CAAC;AAXD,oCAWC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const helpers_1 = require("./helpers");
|
4
|
+
describe('generateSAID test', () => {
|
5
|
+
it('should the hashed result of the abi encoded service agreement', () => {
|
6
|
+
const sa = {
|
7
|
+
payment: '1000000000000000000',
|
8
|
+
expiration: 300,
|
9
|
+
oracles: ['0x9CA9d2D5E04012C9Ed24C0e513C9bfAa4A2dD77f'],
|
10
|
+
endAt: Math.round(new Date('2020-10-19T22:17:19Z').getTime() / 1000),
|
11
|
+
aggregator: '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
|
12
|
+
aggInitiateJobSelector: '0xe16c4c94',
|
13
|
+
aggFulfillSelector: '0x9760168f',
|
14
|
+
requestDigest: '0xbadc0de5badc0de5badc0de5badc0de5badc0de5badc0de5badc0de5badc0de5',
|
15
|
+
};
|
16
|
+
const expected = '0x31e6113ed6267498e525eb904421e8d2e2a90289553334c692f07505c8c059a6';
|
17
|
+
const actual = helpers_1.generateSAID(sa);
|
18
|
+
expect(actual).toEqual(expected);
|
19
|
+
});
|
20
|
+
});
|
21
|
+
//# sourceMappingURL=helpers.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.test.js","sourceRoot":"","sources":["../../src/helpers.test.ts"],"names":[],"mappings":";;AAAA,uCAA0D;AAE1D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;QACvE,MAAM,EAAE,GAAqB;YAC3B,OAAO,EAAE,qBAAqB;YAC9B,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,CAAC,4CAA4C,CAAC;YACvD,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,sBAAsB,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;YACpE,UAAU,EAAE,4CAA4C;YACxD,sBAAsB,EAAE,YAAY;YACpC,kBAAkB,EAAE,YAAY;YAChC,aAAa,EACX,oEAAoE;SACvE,CAAA;QAED,MAAM,QAAQ,GACZ,oEAAoE,CAAA;QACtE,MAAM,MAAM,GAAG,sBAAY,CAAC,EAAE,CAAC,CAAA;QAC/B,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import * as contract from './contract';
|
2
|
+
import * as helpers from './helpers';
|
3
|
+
import * as debug from './debug';
|
4
|
+
import LinkToken from './LinkToken.json';
|
5
|
+
import * as wallet from './wallet';
|
6
|
+
import * as matchers from './matchers';
|
7
|
+
import * as generated from './generated';
|
8
|
+
export { contract, helpers, debug, LinkToken, wallet, matchers, generated };
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
3
|
+
if (mod && mod.__esModule) return mod;
|
4
|
+
var result = {};
|
5
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6
|
+
result["default"] = mod;
|
7
|
+
return result;
|
8
|
+
};
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
11
|
+
};
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
+
const contract = __importStar(require("./contract"));
|
14
|
+
exports.contract = contract;
|
15
|
+
const helpers = __importStar(require("./helpers"));
|
16
|
+
exports.helpers = helpers;
|
17
|
+
const debug = __importStar(require("./debug"));
|
18
|
+
exports.debug = debug;
|
19
|
+
const LinkToken_json_1 = __importDefault(require("./LinkToken.json"));
|
20
|
+
exports.LinkToken = LinkToken_json_1.default;
|
21
|
+
const wallet = __importStar(require("./wallet"));
|
22
|
+
exports.wallet = wallet;
|
23
|
+
const matchers = __importStar(require("./matchers"));
|
24
|
+
exports.matchers = matchers;
|
25
|
+
const generated = __importStar(require("./generated"));
|
26
|
+
exports.generated = generated;
|
27
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAsC;AAQ7B,4BAAQ;AAPjB,mDAAoC;AAOjB,0BAAO;AAN1B,+CAAgC;AAMJ,sBAAK;AALjC,sEAAwC;AAKL,oBAL5B,wBAAS,CAK4B;AAJ5C,iDAAkC;AAIY,wBAAM;AAHpD,qDAAsC;AAGgB,4BAAQ;AAF9D,uDAAwC;AAEwB,8BAAS"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const chai_1 = require("chai");
|
4
|
+
const ethers_1 = require("ethers");
|
5
|
+
// Throws if a and b are not equal, as BN's
|
6
|
+
exports.assertBigNum = (a, b, failureMessage) => chai_1.assert(ethers_1.ethers.utils.bigNumberify(a).eq(ethers_1.ethers.utils.bigNumberify(b)), `BigNum ${a} is not ${b}` + (failureMessage ? ': ' + failureMessage : ''));
|
7
|
+
//# sourceMappingURL=matchers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"matchers.js","sourceRoot":"","sources":["../../src/matchers.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAE7B,mCAA+B;AAG/B,2CAA2C;AAC9B,QAAA,YAAY,GAAG,CAC1B,CAAe,EACf,CAAe,EACf,cAAuB,EACvB,EAAE,CACF,aAAM,CACJ,eAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,eAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAC7D,UAAU,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAC1E,CAAA"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const ethers_1 = require("ethers");
|
7
|
+
const ganache_core_1 = __importDefault(require("ganache-core"));
|
8
|
+
/**
|
9
|
+
* Create a test provider which uses an in-memory, in-process chain
|
10
|
+
*/
|
11
|
+
function makeTestProvider() {
|
12
|
+
return new ethers_1.ethers.providers.Web3Provider(ganache_core_1.default.provider());
|
13
|
+
}
|
14
|
+
exports.makeTestProvider = makeTestProvider;
|
15
|
+
//# sourceMappingURL=provider.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":";;;;;AAAA,mCAA+B;AAC/B,gEAAkC;AAElC;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,OAAO,IAAI,eAAM,CAAC,SAAS,CAAC,YAAY,CAAC,sBAAO,CAAC,QAAQ,EAAS,CAAC,CAAA;AACrE,CAAC;AAFD,4CAEC"}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { ethers } from 'ethers';
|
2
|
+
import { JsonRpcProvider } from 'ethers/providers';
|
3
|
+
interface RCreateFundedWallet {
|
4
|
+
/**
|
5
|
+
* The created wallet
|
6
|
+
*/
|
7
|
+
wallet: ethers.Wallet;
|
8
|
+
/**
|
9
|
+
* The receipt of the tx that funded the created wallet
|
10
|
+
*/
|
11
|
+
receipt: ethers.providers.TransactionReceipt;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Create a pre-funded wallet with all defaults
|
15
|
+
*
|
16
|
+
* @param provider The provider to connect to the created wallet and to withdraw funds from
|
17
|
+
* @param accountIndex The account index of the corresponding wallet derivation path
|
18
|
+
*/
|
19
|
+
export declare function createFundedWallet(provider: JsonRpcProvider, accountIndex: number): Promise<RCreateFundedWallet>;
|
20
|
+
/**
|
21
|
+
* Create an ethers.js wallet instance that is connected to the given provider
|
22
|
+
*
|
23
|
+
* @param provider A compatible ethers.js provider such as the one returned by `ganache.provider()` to connect the wallet to
|
24
|
+
* @param accountIndex The account index to derive from the mnemonic phrase
|
25
|
+
*/
|
26
|
+
export declare function createWallet(provider: ethers.providers.JsonRpcProvider, accountIndex: number): ethers.Wallet;
|
27
|
+
/**
|
28
|
+
* Fund a wallet with unlocked accounts available from the given provider
|
29
|
+
*
|
30
|
+
* @param wallet The ethers wallet to fund
|
31
|
+
* @param provider The provider which has control over unlocked, funded accounts to transfer funds from
|
32
|
+
* @param overrides Transaction parameters to override when sending the funding transaction
|
33
|
+
*/
|
34
|
+
export declare function fundWallet(wallet: ethers.Wallet, provider: ethers.providers.JsonRpcProvider, overrides?: Omit<ethers.providers.TransactionRequest, 'to' | 'from'>): Promise<ethers.providers.TransactionReceipt>;
|
35
|
+
export {};
|
@@ -0,0 +1,64 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const ethers_1 = require("ethers");
|
4
|
+
const debug_1 = require("./debug");
|
5
|
+
/**
|
6
|
+
* Create a pre-funded wallet with all defaults
|
7
|
+
*
|
8
|
+
* @param provider The provider to connect to the created wallet and to withdraw funds from
|
9
|
+
* @param accountIndex The account index of the corresponding wallet derivation path
|
10
|
+
*/
|
11
|
+
async function createFundedWallet(provider, accountIndex) {
|
12
|
+
const wallet = createWallet(provider, accountIndex);
|
13
|
+
const receipt = await fundWallet(wallet, provider);
|
14
|
+
return { wallet, receipt };
|
15
|
+
}
|
16
|
+
exports.createFundedWallet = createFundedWallet;
|
17
|
+
/**
|
18
|
+
* Create an ethers.js wallet instance that is connected to the given provider
|
19
|
+
*
|
20
|
+
* @param provider A compatible ethers.js provider such as the one returned by `ganache.provider()` to connect the wallet to
|
21
|
+
* @param accountIndex The account index to derive from the mnemonic phrase
|
22
|
+
*/
|
23
|
+
function createWallet(provider, accountIndex) {
|
24
|
+
const debug = debug_1.makeDebug('wallet:createWallet');
|
25
|
+
if (accountIndex < 0) {
|
26
|
+
throw Error(`Account index must be greater than 0, got ${accountIndex}`);
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* THIS IS FOR TESTING PURPOSES ONLY
|
30
|
+
*/
|
31
|
+
const mnemonicPhrase = 'dose weasel clever culture letter volume endorse used harvest ripple circle install';
|
32
|
+
const path = `m/44'/60'/${accountIndex}'/0/0`;
|
33
|
+
debug('created wallet with parameters: %o', { mnemonicPhrase, path });
|
34
|
+
return ethers_1.ethers.Wallet.fromMnemonic(mnemonicPhrase, path).connect(provider);
|
35
|
+
}
|
36
|
+
exports.createWallet = createWallet;
|
37
|
+
/**
|
38
|
+
* Fund a wallet with unlocked accounts available from the given provider
|
39
|
+
*
|
40
|
+
* @param wallet The ethers wallet to fund
|
41
|
+
* @param provider The provider which has control over unlocked, funded accounts to transfer funds from
|
42
|
+
* @param overrides Transaction parameters to override when sending the funding transaction
|
43
|
+
*/
|
44
|
+
async function fundWallet(wallet, provider, overrides) {
|
45
|
+
const debug = debug_1.makeDebug('wallet:fundWallet');
|
46
|
+
debug('funding wallet');
|
47
|
+
debug('retreiving accounts...');
|
48
|
+
const nodeOwnedAccounts = await provider.listAccounts();
|
49
|
+
debug('retreived accounts: %o', nodeOwnedAccounts);
|
50
|
+
const signer = provider.getSigner(nodeOwnedAccounts[0]);
|
51
|
+
const txParams = {
|
52
|
+
to: wallet.address,
|
53
|
+
value: ethers_1.ethers.utils.parseEther('10'),
|
54
|
+
...overrides,
|
55
|
+
};
|
56
|
+
debug('sending tx with the following parameters: %o', txParams);
|
57
|
+
const tx = await signer.sendTransaction(txParams);
|
58
|
+
debug('waiting on tx %s to complete...', tx.hash);
|
59
|
+
const receipt = await tx.wait();
|
60
|
+
debug('tx %s confirmed with tx receipt %o', tx.hash, receipt);
|
61
|
+
return receipt;
|
62
|
+
}
|
63
|
+
exports.fundWallet = fundWallet;
|
64
|
+
//# sourceMappingURL=wallet.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":";;AAAA,mCAA+B;AAC/B,mCAAmC;AAcnC;;;;;GAKG;AACI,KAAK,UAAU,kBAAkB,CACtC,QAAyB,EACzB,YAAoB;IAEpB,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;IACnD,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAElD,OAAO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