Merge branch 'master' into next-v5.0
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,36 +1,42 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "erc4626-tests/ERC4626.test.sol";
|
||||
import {ERC4626Test} from "erc4626-tests/ERC4626.test.sol";
|
||||
|
||||
import {SafeCast} from "../../../../contracts/utils/math/SafeCast.sol";
|
||||
import {ERC20Mock} from "../../../../contracts/mocks/ERC20Mock.sol";
|
||||
import {ERC4626Mock} from "../../../../contracts/mocks/ERC4626Mock.sol";
|
||||
import {SafeCast} from "openzeppelin/utils/math/SafeCast.sol";
|
||||
import {ERC20} from "openzeppelin/token/ERC20/ERC20.sol";
|
||||
import {ERC4626} from "openzeppelin/token/ERC20/extensions/ERC4626.sol";
|
||||
|
||||
import {ERC20Mock} from "openzeppelin/mocks/token/ERC20Mock.sol";
|
||||
import {ERC4626Mock} from "openzeppelin/mocks/token/ERC4626Mock.sol";
|
||||
import {ERC4626OffsetMock} from "openzeppelin/mocks/token/ERC4626OffsetMock.sol";
|
||||
|
||||
contract ERC4626VaultOffsetMock is ERC4626OffsetMock {
|
||||
constructor(
|
||||
ERC20 underlying_,
|
||||
uint8 offset_
|
||||
) ERC20("My Token Vault", "MTKNV") ERC4626(underlying_) ERC4626OffsetMock(offset_) {}
|
||||
}
|
||||
|
||||
contract ERC4626StdTest is ERC4626Test {
|
||||
ERC20 private _underlying = new ERC20Mock();
|
||||
|
||||
function setUp() public override {
|
||||
_underlying_ = address(new ERC20Mock());
|
||||
_underlying_ = address(_underlying);
|
||||
_vault_ = address(new ERC4626Mock(_underlying_));
|
||||
_delta_ = 0;
|
||||
_vaultMayBeEmpty = false;
|
||||
_vaultMayBeEmpty = true;
|
||||
_unlimitedAmount = true;
|
||||
}
|
||||
|
||||
// solhint-disable-next-line func-name-mixedcase
|
||||
function test_RT_mint_withdraw(ERC4626Test.Init memory init, uint256 shares) public override {
|
||||
// There is an edge case where we currently behave different than the property tests,
|
||||
// when all assets are lost to negative yield.
|
||||
|
||||
// Sum all initially deposited assets.
|
||||
int256 initAssets = 0;
|
||||
for (uint256 i = 0; i < init.share.length; i++) {
|
||||
vm.assume(init.share[i] <= uint256(type(int256).max - initAssets));
|
||||
initAssets += SafeCast.toInt256(init.share[i]);
|
||||
}
|
||||
|
||||
// Reject tests where the yield loses all assets from the vault.
|
||||
vm.assume(init.yield > -initAssets);
|
||||
|
||||
super.test_RT_mint_withdraw(init, shares);
|
||||
/**
|
||||
* @dev Check the case where calculated `decimals` value overflows the `uint8` type.
|
||||
*/
|
||||
function testFuzzDecimalsOverflow(uint8 offset) public {
|
||||
/// @dev Remember that the `_underlying` exhibits a `decimals` value of 18.
|
||||
offset = uint8(bound(uint256(offset), 238, uint256(type(uint8).max)));
|
||||
ERC4626VaultOffsetMock erc4626VaultOffsetMock = new ERC4626VaultOffsetMock(_underlying, offset);
|
||||
vm.expectRevert();
|
||||
erc4626VaultOffsetMock.decimals();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@ const Wallet = require('ethereumjs-wallet').default;
|
||||
|
||||
const ERC20Permit = artifacts.require('$ERC20Permit');
|
||||
|
||||
const { EIP712Domain, Permit, domainSeparator } = require('../../../helpers/eip712');
|
||||
const { Permit, getDomain, domainType, domainSeparator } = require('../../../helpers/eip712');
|
||||
const { getChainId } = require('../../../helpers/chainid');
|
||||
|
||||
contract('ERC20Permit', function (accounts) {
|
||||
@ -34,9 +34,7 @@ contract('ERC20Permit', function (accounts) {
|
||||
});
|
||||
|
||||
it('domain separator', async function () {
|
||||
expect(await this.token.DOMAIN_SEPARATOR()).to.equal(
|
||||
await domainSeparator({ name, version, chainId: this.chainId, verifyingContract: this.token.address }),
|
||||
);
|
||||
expect(await this.token.DOMAIN_SEPARATOR()).to.equal(await getDomain(this.token).then(domainSeparator));
|
||||
});
|
||||
|
||||
describe('permit', function () {
|
||||
@ -47,17 +45,18 @@ contract('ERC20Permit', function (accounts) {
|
||||
const nonce = 0;
|
||||
const maxDeadline = MAX_UINT256;
|
||||
|
||||
const buildData = (chainId, verifyingContract, deadline = maxDeadline) => ({
|
||||
primaryType: 'Permit',
|
||||
types: { EIP712Domain, Permit },
|
||||
domain: { name, version, chainId, verifyingContract },
|
||||
message: { owner, spender, value, nonce, deadline },
|
||||
});
|
||||
const buildData = (contract, deadline = maxDeadline) =>
|
||||
getDomain(contract).then(domain => ({
|
||||
primaryType: 'Permit',
|
||||
types: { EIP712Domain: domainType(domain), Permit },
|
||||
domain,
|
||||
message: { owner, spender, value, nonce, deadline },
|
||||
}));
|
||||
|
||||
it('accepts owner signature', async function () {
|
||||
const data = buildData(this.chainId, this.token.address);
|
||||
const signature = ethSigUtil.signTypedMessage(wallet.getPrivateKey(), { data });
|
||||
const { v, r, s } = fromRpcSig(signature);
|
||||
const { v, r, s } = await buildData(this.token)
|
||||
.then(data => ethSigUtil.signTypedMessage(wallet.getPrivateKey(), { data }))
|
||||
.then(fromRpcSig);
|
||||
|
||||
await this.token.permit(owner, spender, value, maxDeadline, v, r, s);
|
||||
|
||||
@ -66,9 +65,9 @@ contract('ERC20Permit', function (accounts) {
|
||||
});
|
||||
|
||||
it('rejects reused signature', async function () {
|
||||
const data = buildData(this.chainId, this.token.address);
|
||||
const signature = ethSigUtil.signTypedMessage(wallet.getPrivateKey(), { data });
|
||||
const { v, r, s } = fromRpcSig(signature);
|
||||
const { v, r, s } = await buildData(this.token)
|
||||
.then(data => ethSigUtil.signTypedMessage(wallet.getPrivateKey(), { data }))
|
||||
.then(fromRpcSig);
|
||||
|
||||
await this.token.permit(owner, spender, value, maxDeadline, v, r, s);
|
||||
|
||||
@ -80,9 +79,10 @@ contract('ERC20Permit', function (accounts) {
|
||||
|
||||
it('rejects other signature', async function () {
|
||||
const otherWallet = Wallet.generate();
|
||||
const data = buildData(this.chainId, this.token.address);
|
||||
const signature = ethSigUtil.signTypedMessage(otherWallet.getPrivateKey(), { data });
|
||||
const { v, r, s } = fromRpcSig(signature);
|
||||
|
||||
const { v, r, s } = await buildData(this.token)
|
||||
.then(data => ethSigUtil.signTypedMessage(otherWallet.getPrivateKey(), { data }))
|
||||
.then(fromRpcSig);
|
||||
|
||||
await expectRevert(
|
||||
this.token.permit(owner, spender, value, maxDeadline, v, r, s),
|
||||
@ -93,9 +93,9 @@ contract('ERC20Permit', function (accounts) {
|
||||
it('rejects expired permit', async function () {
|
||||
const deadline = (await time.latest()) - time.duration.weeks(1);
|
||||
|
||||
const data = buildData(this.chainId, this.token.address, deadline);
|
||||
const signature = ethSigUtil.signTypedMessage(wallet.getPrivateKey(), { data });
|
||||
const { v, r, s } = fromRpcSig(signature);
|
||||
const { v, r, s } = await buildData(this.token, deadline)
|
||||
.then(data => ethSigUtil.signTypedMessage(wallet.getPrivateKey(), { data }))
|
||||
.then(fromRpcSig);
|
||||
|
||||
await expectRevert(this.token.permit(owner, spender, value, deadline, v, r, s), 'ERC20Permit: expired deadline');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user