Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
use POL mock
Browse files Browse the repository at this point in the history
  • Loading branch information
simonDos committed Nov 9, 2023
1 parent a2b6042 commit b0ccafe
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 38 deletions.
56 changes: 56 additions & 0 deletions contracts/common/tokens/POLTokenMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol";
import "openzeppelin-solidity/contracts/utils/Address.sol";


contract POLTokenMock is ERC20Mintable {
using Address for address;

// detailed ERC20
string public name;
string public symbol;
uint8 public decimals = 18;

constructor(string memory _name, string memory _symbol) public {
name = _name;
symbol = _symbol;

uint256 value = 10**10 * (10**18);
mint(msg.sender, value);
}

function safeTransfer(IERC20 token, address to, uint256 value) public {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}

function safeTransferFrom(IERC20 token, address from, address to, uint256 value) public {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}

/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must equal true).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.

// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.

require(address(token).isContract());

// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success);

if (returndata.length > 0) { // Return data is optional
require(abi.decode(returndata, (bool)));
}
}
}
37 changes: 0 additions & 37 deletions contracts/common/tokens/TestToken.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol";
import "openzeppelin-solidity/contracts/utils/Address.sol";

contract TestToken is ERC20Mintable {
using Address for address;

// detailed ERC20
string public name;
string public symbol;
Expand All @@ -18,38 +15,4 @@ contract TestToken is ERC20Mintable {
uint256 value = 10**10 * (10**18);
mint(msg.sender, value);
}

function safeTransfer(IERC20 token, address to, uint256 value) public {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}

function safeTransferFrom(IERC20 token, address from, address to, uint256 value) public {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}

/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must equal true).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.

// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.

require(address(token).isContract());

// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success);

if (returndata.length > 0) { // Return data is optional
require(abi.decode(returndata, (bool)));
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"mnemonics": "clock radar mass judge dismiss just intact mind resemble fringe diary casino"
},
"devDependencies": {
"@types/node": "11.1.0",
"@openzeppelin/test-helpers": "^0.5.5",
"babel-cli": "^6.26.0",
"babel-eslint": "10.0.1",
Expand Down
1 change: 1 addition & 0 deletions test/helpers/artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const TransferWithSigPredicate = artifacts.require(

// tokens
export const MaticWETH = artifacts.require('MaticWETH')
export const POLTokenMock = artifacts.require('POLTokenMock')
export const TestToken = artifacts.require('TestToken')
export const RootERC721 = artifacts.require('RootERC721')
export const ERC721PlasmaMintable = artifacts.require('ERC721PlasmaMintable')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/root/DepositManagerUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract('DepositManager Update @skip-on-coverage', async function(accounts) {
registry.contract.methods.updateContractMap(ethUtils.keccak256('polygonMigration'), polygonMigrationTest.address).encodeABI()
)

pol = await artifacts.TestToken.new('Polygon Ecosystem Token', 'POL')
pol = await artifacts.POLTokenMock.new('Polygon Ecosystem Token', 'POL')

await governance.update(
registry.address,
Expand Down

0 comments on commit b0ccafe

Please sign in to comment.