|
1 | 1 | import action from './router';
|
2 |
| -import { fixtureContractData, fixtureCtx, fixtureRuntime } from '../../test/fixtures'; |
| 2 | +import { fixtureContractData, fixtureCtx, fixtureRuntime, fixtureSigner, mockDeployTransaction } from '../../test/fixtures'; |
3 | 3 |
|
4 | 4 | describe('steps/router.ts', () => {
|
5 | 5 | describe('configInject()', () => {
|
@@ -47,4 +47,55 @@ describe('steps/router.ts', () => {
|
47 | 47 | expect(result.contractAddresses.GreeterTwo).toStrictEqual(contracts.GreeterTwo.address);
|
48 | 48 | });
|
49 | 49 | });
|
| 50 | + |
| 51 | + describe('exec()', () => { |
| 52 | + it('throws an error on missing contract file', async () => { |
| 53 | + const contracts = { Greeter: fixtureContractData('Greeter') }; |
| 54 | + const step = { |
| 55 | + name: 'router-test', |
| 56 | + version: '0.0.0', |
| 57 | + currentLabel: 'router.Router', |
| 58 | + }; |
| 59 | + |
| 60 | + const runtime = fixtureRuntime(); |
| 61 | + const ctx = fixtureCtx({}); // generate a ctx without the contracts |
| 62 | + const config = { contracts: Object.keys(contracts) }; |
| 63 | + |
| 64 | + await expect(action.exec(runtime, ctx, config, step)).rejects.toThrow('contract not found: Greeter'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('generates and deploys Router with a single contract', async () => { |
| 68 | + const signer = fixtureSigner(); |
| 69 | + const contracts = { Greeter: fixtureContractData('Greeter') }; |
| 70 | + |
| 71 | + const step = { |
| 72 | + name: 'router-test', |
| 73 | + version: '0.0.0', |
| 74 | + currentLabel: 'router.Router', |
| 75 | + }; |
| 76 | + |
| 77 | + const runtime = fixtureRuntime(); |
| 78 | + const ctx = fixtureCtx({ contracts }); |
| 79 | + const config = { from: await signer.getAddress(), contracts: Object.keys(contracts) }; |
| 80 | + |
| 81 | + jest.spyOn(runtime, 'getSigner').mockResolvedValue(signer); |
| 82 | + |
| 83 | + const { tx, rx } = await mockDeployTransaction(signer); |
| 84 | + const res = await action.exec(runtime, ctx, config, step); |
| 85 | + |
| 86 | + expect(signer.sendTransaction).toHaveBeenCalledTimes(1); |
| 87 | + expect(tx.wait).toHaveBeenCalledTimes(1); |
| 88 | + |
| 89 | + expect(res.contracts).toMatchObject({ |
| 90 | + Router: { |
| 91 | + address: rx.contractAddress, |
| 92 | + abi: contracts.Greeter.abi, |
| 93 | + deployedOn: step.currentLabel, |
| 94 | + deployTxnHash: tx.hash, |
| 95 | + contractName: 'Router', |
| 96 | + sourceName: 'Router.sol', |
| 97 | + }, |
| 98 | + }); |
| 99 | + }); |
| 100 | + }); |
50 | 101 | });
|
0 commit comments