* `@0x/contracts-utils`: Convert more 0.6 contracts * `@0x/contracts-erc20`: Add solidity 0.6 contracts. * `@0x/utils`: Add new `ZeroExRevertErrors` revert types * `@0x/contracts-zero-ex`: Introduce the `TransformERC20` feature. * `@0x/subproviders`: Update ganache-core. `@0x/web3-wrapper`: Update ganache-core. * `@0x/contracts-zero-ex`: Make `TokenSpender`'s puppet contract a distinct contract type and rename `getTokenSpenderPuppet()` to `getAllowanceTarget()` * `@0x/zero-ex`: Rebase and use "slot" instead of "offset" language in storage buckets. * `@0x/web3-wrapper`: Add `getAccountNonceAsync()` to `Web3Wrapper` * `@0x/contracts-zero-ex`: Revamp TransformERC20. * `@0x/contracts-zero-ex`: Remove `payable` from `IERC20Transformer.transform()` and disable hex capitalization linter rule because of prettier conflicts. * `@0x/contracts-zero-ex`: Use `immutable` owner in `Puppet` instead of `Ownable`. * `@x/utils`: Address review feedback. * `@0x/contracts-zero-ex`: Address review feedback. * `@0x/contracts-utils`: Address review feedback. * `@0x/contracts-zero-ex`: Return deployment nonce in `transform()`. * `@0x/contracts-zero-ex`: Finish returning deployment nonce in `transform()`. * `@0x/contracts-zero-ex`: Fix doc-gen bug. * `@0x/contracts-zero-ex`: Address review comments. * `@0x/utils`: Add `NegativeTransformERC20OutputERror` * `@0x/contracts-zero-ex`: Revert if the taker's output amount decreases. Co-authored-by: Lawrence Forman <me@merklejerk.com>
		
			
				
	
	
		
			83 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { blockchainTests, constants, expect, randomAddress, verifyEventsFromLogs } from '@0x/contracts-test-utils';
 | |
| import { AuthorizableRevertErrors, hexUtils, StringRevertError } from '@0x/utils';
 | |
| 
 | |
| import { artifacts } from './artifacts';
 | |
| import { AllowanceTargetContract, TestCallTargetContract, TestCallTargetEvents } from './wrappers';
 | |
| 
 | |
| blockchainTests.resets('AllowanceTarget', env => {
 | |
|     let owner: string;
 | |
|     let authority: string;
 | |
|     let allowanceTarget: AllowanceTargetContract;
 | |
|     let callTarget: TestCallTargetContract;
 | |
| 
 | |
|     before(async () => {
 | |
|         [owner, authority] = await env.getAccountAddressesAsync();
 | |
|         allowanceTarget = await AllowanceTargetContract.deployFrom0xArtifactAsync(
 | |
|             artifacts.AllowanceTarget,
 | |
|             env.provider,
 | |
|             env.txDefaults,
 | |
|             artifacts,
 | |
|         );
 | |
|         await allowanceTarget.addAuthorizedAddress(authority).awaitTransactionSuccessAsync();
 | |
|         callTarget = await TestCallTargetContract.deployFrom0xArtifactAsync(
 | |
|             artifacts.TestCallTarget,
 | |
|             env.provider,
 | |
|             env.txDefaults,
 | |
|             artifacts,
 | |
|         );
 | |
|     });
 | |
| 
 | |
|     const TARGET_RETURN_VALUE = hexUtils.rightPad('0x12345678');
 | |
|     const REVERTING_DATA = '0x1337';
 | |
| 
 | |
|     describe('executeCall()', () => {
 | |
|         it('non-authority cannot call executeCall()', async () => {
 | |
|             const notAuthority = randomAddress();
 | |
|             const tx = allowanceTarget
 | |
|                 .executeCall(randomAddress(), hexUtils.random())
 | |
|                 .callAsync({ from: notAuthority });
 | |
|             return expect(tx).to.revertWith(new AuthorizableRevertErrors.SenderNotAuthorizedError(notAuthority));
 | |
|         });
 | |
| 
 | |
|         it('authority can call executeCall()', async () => {
 | |
|             const targetData = hexUtils.random(128);
 | |
|             const receipt = await allowanceTarget
 | |
|                 .executeCall(callTarget.address, targetData)
 | |
|                 .awaitTransactionSuccessAsync({ from: authority });
 | |
|             verifyEventsFromLogs(
 | |
|                 receipt.logs,
 | |
|                 [
 | |
|                     {
 | |
|                         context: callTarget.address,
 | |
|                         sender: allowanceTarget.address,
 | |
|                         data: targetData,
 | |
|                         value: constants.ZERO_AMOUNT,
 | |
|                     },
 | |
|                 ],
 | |
|                 TestCallTargetEvents.CallTargetCalled,
 | |
|             );
 | |
|         });
 | |
| 
 | |
|         it('AllowanceTarget returns call result', async () => {
 | |
|             const result = await allowanceTarget
 | |
|                 .executeCall(callTarget.address, hexUtils.random(128))
 | |
|                 .callAsync({ from: authority });
 | |
|             expect(result).to.eq(TARGET_RETURN_VALUE);
 | |
|         });
 | |
| 
 | |
|         it('AllowanceTarget returns raw call revert', async () => {
 | |
|             const tx = allowanceTarget.executeCall(callTarget.address, REVERTING_DATA).callAsync({ from: authority });
 | |
|             return expect(tx).to.revertWith(new StringRevertError('TestCallTarget/REVERT'));
 | |
|         });
 | |
| 
 | |
|         it('AllowanceTarget cannot receive ETH', async () => {
 | |
|             const tx = env.web3Wrapper.sendTransactionAsync({
 | |
|                 to: allowanceTarget.address,
 | |
|                 from: owner,
 | |
|                 value: 0,
 | |
|             });
 | |
|             return expect(tx).to.eventually.be.rejected();
 | |
|         });
 | |
|     });
 | |
| });
 |