Stack too deep when compiling inline assembly Error

This commit is contained in:
Thrilok Kumar 2020-07-31 20:03:21 +05:30
parent eb1dc5d665
commit 2c8bad40fb
8 changed files with 169 additions and 41 deletions

View File

@ -10,7 +10,7 @@ contract DSMath {
z = SafeMath.add(x, y);
}
function sub(uint x, uint y) internal pure returns (uint z) {
function sub(uint x, uint y) internal virtual pure returns (uint z) {
z = SafeMath.sub(x, y);
}

View File

@ -318,6 +318,6 @@ contract OneInchResolver is OneInchResolverHelpers {
}
}
contract ConnectOne is OneInchResolver {
contract ConnectOneInch is OneInchResolver {
string public name = "1Inch-v1";
}

View File

@ -1,7 +1,7 @@
pragma solidity ^0.6.0;
import { InstaMapping } from "../mapping/staking.sol";
import { InstaStakingMapping } from "../mapping/staking.sol";
contract MockInstaMapping is InstaMapping {
contract MockInstaMapping is InstaStakingMapping {
modifier isChief override {_;}
}

View File

@ -0,0 +1,20 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import { ConnectOne } from "../connectors/1proto.sol";
contract MockConnectOne is ConnectOne {
address public oneProtoAddr;
constructor(address _oneProtoAddr) public {
oneProtoAddr = _oneProtoAddr;
}
function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {}
function setUint(uint setId, uint val) override internal {}
function sub(uint x, uint y) internal override pure returns (uint z) {
z = 100000;
}
}

52
package-lock.json generated
View File

@ -1427,7 +1427,7 @@
"eth-lib": "0.2.7",
"ethereumjs-common": "^1.3.2",
"ethereumjs-tx": "^2.1.1",
"scrypt-shim": "github:web3-js/scrypt-shim",
"scrypt-shim": "github:web3-js/scrypt-shim#aafdadda13e660e25e1c525d1f5b2443f5eb1ebb",
"underscore": "1.9.1",
"uuid": "3.3.2",
"web3-core": "1.2.2",
@ -1532,7 +1532,7 @@
"requires": {
"underscore": "1.9.1",
"web3-core-helpers": "1.2.2",
"websocket": "github:web3-js/WebSocket-Node#polyfill/globalThis"
"websocket": "github:web3-js/WebSocket-Node#ef5ea2f41daf4a2113b80c9223df884b4d56c400"
}
},
"web3-shh": {
@ -4958,8 +4958,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"aproba": {
"version": "1.2.0",
@ -4980,14 +4979,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -5002,20 +4999,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -5132,8 +5126,7 @@
"inherits": {
"version": "2.0.4",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -5145,7 +5138,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -5160,7 +5152,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -5168,14 +5159,12 @@
"minimist": {
"version": "1.2.5",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.9.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -5194,7 +5183,6 @@
"version": "0.5.3",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "^1.2.5"
}
@ -5256,8 +5244,7 @@
"npm-normalize-package-bin": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"npm-packlist": {
"version": "1.4.8",
@ -5285,8 +5272,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
@ -5298,7 +5284,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -5376,8 +5361,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
@ -5413,7 +5397,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -5433,7 +5416,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -5477,14 +5459,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},
@ -11678,7 +11658,7 @@
"requires": {
"underscore": "1.9.1",
"web3-core-helpers": "1.2.1",
"websocket": "github:web3-js/WebSocket-Node#polyfill/globalThis"
"websocket": "github:web3-js/WebSocket-Node#905deb4812572b344f5801f8c9ce8bb02799d82e"
},
"dependencies": {
"debug": {
@ -11695,7 +11675,7 @@
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"websocket": {
"version": "github:web3-js/WebSocket-Node#ef5ea2f41daf4a2113b80c9223df884b4d56c400",
"version": "github:web3-js/WebSocket-Node#905deb4812572b344f5801f8c9ce8bb02799d82e",
"from": "github:web3-js/WebSocket-Node#polyfill/globalThis",
"requires": {
"debug": "^2.2.0",

View File

@ -9,7 +9,7 @@
"coverage": "./node_modules/.bin/solidity-coverage",
"solium": "solium -d contracts/",
"build-contracts": "sol-merger \"./contracts/connectors/mock.sol\" ./contracts/build",
"ganache": "ganache-cli --deterministic --unlock 0xfcd22438ad6ed564a1c26151df73f6b33b817b56 -f https://mainnet.infura.io/v3/<Your Key>"
"ganache": "ganache-cli"
},
"repository": {
"type": "git",

1
test/abi/1proto.json Normal file

File diff suppressed because one or more lines are too long

127
test/oneProto.js Normal file
View File

@ -0,0 +1,127 @@
const {
BN, // Big Number support
expectEvent, // Assertions for emitted events
expectRevert, // Assertions for transactions that should fail
balance,
ether
} = require('@openzeppelin/test-helpers');
const MockContract = artifacts.require("MockContract");
const MockConnectOne = artifacts.require('MockConnectOne');
const erc20ABI = require("./abi/erc20.js");
const oneProto = require("./abi/1proto.json");
contract('ConnectOneProto', async accounts => {
const [sender, receiver] = accounts;
let mock, mockConnectOneProto, oneProtoContract, sellToken, buyToken, sellAmt;
before(async function () {
mock = await MockContract.new();
mockConnectOneProto = await MockConnectOne.new(mock.address);
oneProtoContract = new web3.eth.Contract(oneProto, mock.address);
sellToken = new web3.eth.Contract(erc20ABI, mock.address);
buyToken = new web3.eth.Contract(erc20ABI, mock.address);
sellAmt = String(20 * 10 ** 18);
// mocking balanceOf
let balanceOf = await sellToken.methods.balanceOf(mockConnectOneProto.address).encodeABI();
await mock.givenMethodReturnUint(balanceOf, sellAmt);
// mocking balanceOf
let decimals = await sellToken.methods.decimals().encodeABI();
await mock.givenMethodReturnUint(decimals, 18);
// mocking balanceOf
let decimalsBuy = await buyToken.methods.decimals().encodeABI();
await mock.givenMethodReturnUint(decimalsBuy, 18);
// mocking approve
let approve = await sellToken.methods.approve(mockConnectOneProto.address, sellAmt).encodeABI();
await mock.givenMethodReturnBool(approve, "true");
})
it('can sell DAI <> USDC', async function() {
let getExpectedReturn = await oneProtoContract.methods.getExpectedReturn(
mock.address,
mock.address,
sellAmt,
5,
0
).encodeABI();
await mock.givenMethodReturnUint(getExpectedReturn, String(sellAmt));
// mocking stake
let swapWithReferral = await oneProtoContract.methods.swapWithReferral(
mock.address,
mock.address,
sellAmt,
1,
[0,1,0],
0,
mock.address,
0
).encodeABI();
await mock.givenMethodReturnBool(swapWithReferral, "true");
const tx = await mockConnectOneProto.sell(
mock.address,
mock.address,
sellAmt,
String(99 * 10 ** 16),
0,
0
)
let obj = {
buyAmt: 100000
};
expectEvent(tx, "LogSell", obj);
});
// it('can withdraw', async function() {
// // mocking withdraw
// let withdraw = await stakingContract.methods.withdraw(10000000).encodeABI();
// await mock.givenMethodReturnBool(withdraw, "true");
// // mocking getReward
// let reward = await stakingContract.methods.getReward().encodeABI();
// await mock.givenMethodReturnBool(reward, "true");
// const tx = await mockSynthetixStaking.withdraw(
// "snx",
// 10000000,
// 0,
// 111,
// 112
// )
// expectEvent(tx, "LogWithdraw");
// expectEvent(tx, "LogClaimedReward");
// });
// it('can claim reward', async function() {
// // mocking getReward
// let reward = await stakingContract.methods.getReward().encodeABI();
// await mock.givenMethodReturnBool(reward, "true");
// const tx = await mockSynthetixStaking.claimReward(
// "snx",
// 112
// )
// expectEvent(tx, "LogClaimedReward");
// });
// it('cannot deposit if pool removed', async function() {
// mockInstaMapping.removeStakingMapping('snx', mock.address);
// // mocking stake
// let stake = await stakingContract.methods.stake(10000000).encodeABI();
// await mock.givenMethodReturnBool(stake, "true");
// const tx = mockSynthetixStaking.deposit(
// "snx",
// 10000000,
// 0,
// 0
// )
// expectRevert(tx, "Wrong Staking Name");
// });
})