update getMappingAddr with virtual;

Update MockSynthetix to override getMappingAddr;
Update test case for adding and removing pool on mapping;
This commit is contained in:
Lecky Lao 2020-07-15 00:53:21 +10:00
parent df61aebc58
commit 9ce77c1336
3 changed files with 29 additions and 10 deletions

View File

@ -27,7 +27,7 @@ contract SynthetixStakingHelper is DSMath, Stores {
/** /**
* @dev Return InstaDApp Synthetix Mapping Addresses * @dev Return InstaDApp Synthetix Mapping Addresses
*/ */
function getMappingAddr() internal pure returns (address) { function getMappingAddr() virtual internal view returns (address) {
return 0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88; // InstaMapping Address return 0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88; // InstaMapping Address
} }

View File

@ -1,23 +1,26 @@
pragma solidity ^0.6.0; pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import { ConnectSynthetixStaking } from "../connectors/synthetix.sol"; import { ConnectSynthetixStaking } from "../connectors/synthetix.sol";
contract MockSynthetixStaking is ConnectSynthetixStaking{ contract MockSynthetixStaking is ConnectSynthetixStaking{
address public synthetixStakingAddr; address public synthetixStakingAddr;
address public instaMappingAddr;
constructor(address _synthetixStakingAddr) public { constructor(address _synthetixStakingAddr, address _instaMappingAddr) public {
synthetixStakingAddr = _synthetixStakingAddr; synthetixStakingAddr = _synthetixStakingAddr;
instaMappingAddr = _instaMappingAddr;
} }
// function getSynthetixStakingAddr(address token) override internal returns (address) {
// return synthetixStakingAddr;
// }
function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {} function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {}
function getSnxAddr() override internal view returns (address) { function getSnxAddr() override internal view returns (address) {
return synthetixStakingAddr; return synthetixStakingAddr;
} }
function getMappingAddr() override internal view returns (address) {
return instaMappingAddr;
}
function setUint(uint setId, uint val) override internal {} function setUint(uint setId, uint val) override internal {}
} }

View File

@ -20,7 +20,7 @@ contract('ConnectSynthetixStaking', async accounts => {
before(async function () { before(async function () {
mock = await MockContract.new(); mock = await MockContract.new();
mockInstaMapping = await MockInstaMapping.new(); mockInstaMapping = await MockInstaMapping.new();
mockSynthetixStaking = await MockSynthetixStaking.new(mock.address); mockSynthetixStaking = await MockSynthetixStaking.new(mock.address, mockInstaMapping.address);
stakingContract = new web3.eth.Contract(synthetixStaking, mock.address); stakingContract = new web3.eth.Contract(synthetixStaking, mock.address);
token = new web3.eth.Contract(erc20ABI, mock.address); token = new web3.eth.Contract(erc20ABI, mock.address);
mockInstaMapping.addStakingMapping('snx', mock.address, mock.address); mockInstaMapping.addStakingMapping('snx', mock.address, mock.address);
@ -41,7 +41,7 @@ contract('ConnectSynthetixStaking', async accounts => {
await mock.givenMethodReturnBool(stake, "true"); await mock.givenMethodReturnBool(stake, "true");
const tx = await mockSynthetixStaking.deposit( const tx = await mockSynthetixStaking.deposit(
mock.address, "snx",
10000000, 10000000,
0, 0,
0 0
@ -58,7 +58,7 @@ contract('ConnectSynthetixStaking', async accounts => {
await mock.givenMethodReturnBool(reward, "true"); await mock.givenMethodReturnBool(reward, "true");
const tx = await mockSynthetixStaking.withdraw( const tx = await mockSynthetixStaking.withdraw(
mock.address, "snx",
10000000, 10000000,
0, 0,
111, 111,
@ -73,9 +73,25 @@ contract('ConnectSynthetixStaking', async accounts => {
let reward = await stakingContract.methods.getReward().encodeABI(); let reward = await stakingContract.methods.getReward().encodeABI();
await mock.givenMethodReturnBool(reward, "true"); await mock.givenMethodReturnBool(reward, "true");
const tx = await mockSynthetixStaking.claimReward( const tx = await mockSynthetixStaking.claimReward(
mock.address, "snx",
112 112
) )
expectEvent(tx, "LogClaimedReward"); 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");
});
}) })