mirror of openzeppelin-contracts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openzeppelin-contracts/contracts/mocks/ERC777SenderRecipientMock.sol

153 lines
4.3 KiB

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
import "../token/ERC777/IERC777.sol";
import "../token/ERC777/IERC777Sender.sol";
import "../token/ERC777/IERC777Recipient.sol";
import "../utils/Context.sol";
import "../utils/introspection/IERC1820Registry.sol";
import "../utils/introspection/ERC1820Implementer.sol";
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient, ERC1820Implementer {
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
event TokensToSendCalled(
address operator,
address from,
address to,
uint256 amount,
bytes data,
bytes operatorData,
address token,
uint256 fromBalance,
uint256 toBalance
);
event TokensReceivedCalled(
address operator,
address from,
address to,
uint256 amount,
bytes data,
bytes operatorData,
address token,
uint256 fromBalance,
uint256 toBalance
);
// Emitted in ERC777Mock. Here for easier decoding
event BeforeTokenTransfer();
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
bool private _shouldRevertSend;
bool private _shouldRevertReceive;
IERC1820Registry private _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
bytes32 constant private _TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender");
bytes32 constant private _TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
function tokensToSend(
address operator,
address from,
address to,
uint256 amount,
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
bytes calldata userData,
bytes calldata operatorData
) external override {
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
if (_shouldRevertSend) {
revert();
}
IERC777 token = IERC777(_msgSender());
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
uint256 fromBalance = token.balanceOf(from);
// when called due to burn, to will be the zero address, which will have a balance of 0
uint256 toBalance = token.balanceOf(to);
emit TokensToSendCalled(
operator,
from,
to,
amount,
userData,
operatorData,
address(token),
fromBalance,
toBalance
);
}
function tokensReceived(
address operator,
address from,
address to,
uint256 amount,
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
bytes calldata userData,
bytes calldata operatorData
) external override {
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
if (_shouldRevertReceive) {
revert();
}
IERC777 token = IERC777(_msgSender());
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
uint256 fromBalance = token.balanceOf(from);
// when called due to burn, to will be the zero address, which will have a balance of 0
uint256 toBalance = token.balanceOf(to);
emit TokensReceivedCalled(
operator,
from,
to,
amount,
userData,
operatorData,
address(token),
fromBalance,
toBalance
);
}
function senderFor(address account) public {
_registerInterfaceForAddress(_TOKENS_SENDER_INTERFACE_HASH, account);
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
address self = address(this);
if (account == self) {
registerSender(self);
}
}
function registerSender(address sender) public {
_erc1820.setInterfaceImplementer(address(this), _TOKENS_SENDER_INTERFACE_HASH, sender);
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
}
function recipientFor(address account) public {
_registerInterfaceForAddress(_TOKENS_RECIPIENT_INTERFACE_HASH, account);
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
address self = address(this);
if (account == self) {
registerRecipient(self);
}
}
function registerRecipient(address recipient) public {
_erc1820.setInterfaceImplementer(address(this), _TOKENS_RECIPIENT_INTERFACE_HASH, recipient);
Feature/erc777 #1159 (#1684) * IERC777 from specs, constants returned, up to defaultOperators. (#1159) * IERC777 oprarator approvals (#1159) * ERC777 oprarator approvals fixes and tests * IERC777 send and receive with ERC820 (#1159) * ERC777 Add burn functions and fix send functions (#1159) * ERC777 Make expectEvent compatible with web3.js 1.0 (#1159) * ERC777 Add ERC820 deploy script (#1159) * ERC777 Complete implementation of ERC777 (#1159) This implementation conforms to the current EIP * ERC777 Update ERC820 Registry contract to final version (#1159) * ERC777 Move contracts to 'drafts' folder (#1159) * ERC777: Update to ERC1820 registry and linter error fix (#1159) * ERC777: implement recent changes of EIP777 (#1159) * ERC777 Fix formatting (#1159) * ERC777 Update to solc 0.5.2 (#1159) * ERC777 Fix travis CI errors (#1159) * ERC777 Fix linter errors again... (#1159) * ERC777 Fix unit test (#1159) * ERC777 Fix unit test again (#1159) * Remove extra newlines. * Rename ERC777Base to ERC777. * Remove 'Token' from contract names. * Replace ops for operators. * Move operator check out of _send. * Remove ERC777Burnable. * Remove ERC1820Client, now using the interface directly. * Minor internal refactors in contracts. * Delete extra test helpers. * Simplified tests. * Add basic 777 tests. * Add granularity send test. * Add first operator send tests. * Add burn tests. * Refactor send and burn tests. * Improve send burn refactor. * Greatly improve test module. * Burn instead of send removed tokens. * Add operator tests. * Improve send tests under changing operators. * Refactor and merge send and burn tests. * Add missing and not-implemented tests. * Make _burn private. * Fix typo. * Greatly improve tokensToSend tests. * Refactor hook tests. * Fix hook tests. * Update openzeppelin-test-helpers and ERC1820 address. * Fix natspec indentation. * Make interface functions external. * Remove redundant private revoke and authorize functions. * Improved readability of if statement. * Remove unnecessary asserts. * Add non-one granularity test. * Fix hook call order in _mint. * Fix _mint not reverting on failure to implement tokensReceived. * Remove special case in operatorFn when from is 0. * Refactor ERC777SenderMock. * Add tokensReceived tests. * switch to updated ganache-cli-coverage fork * Fix linter errors. * Add mint tests. * Fix linter errors. * Fix tests. * Update test/drafts/ERC777/ERC777.test.js Co-Authored-By: nventuro <nicolas.venturo@gmail.com> * Add changelog entry.
6 years ago
}
function setShouldRevertSend(bool shouldRevert) public {
_shouldRevertSend = shouldRevert;
}
function setShouldRevertReceive(bool shouldRevert) public {
_shouldRevertReceive = shouldRevert;
}
function send(IERC777 token, address to, uint256 amount, bytes memory data) public {
// This is 777's send function, not the Solidity send function
token.send(to, amount, data); // solhint-disable-line check-send-result
}
function burn(IERC777 token, uint256 amount, bytes memory data) public {
token.burn(amount, data);
}
}