diff --git a/implementation/contracts/deposit/DepositUtils.sol b/implementation/contracts/deposit/DepositUtils.sol index 7e56b2f2f..04c8790c4 100644 --- a/implementation/contracts/deposit/DepositUtils.sol +++ b/implementation/contracts/deposit/DepositUtils.sol @@ -382,9 +382,10 @@ library DepositUtils { /// @return The amount seized in wei. function seizeSignerBonds(Deposit storage _d) internal returns (uint256) { uint256 _preCallBalance = address(this).balance; + IBondedECDSAKeep _keep = IBondedECDSAKeep(_d.keepAddress); - _keep.closeKeep(); _keep.seizeSignerBonds(); + uint256 _postCallBalance = address(this).balance; require(_postCallBalance > _preCallBalance, "No funds received, unexpected"); return _postCallBalance.sub(_preCallBalance); diff --git a/implementation/contracts/test/keep/ECDSAKeepStub.sol b/implementation/contracts/test/keep/ECDSAKeepStub.sol index 56b8c2a5b..0f0e79317 100644 --- a/implementation/contracts/test/keep/ECDSAKeepStub.sol +++ b/implementation/contracts/test/keep/ECDSAKeepStub.sol @@ -1,47 +1,53 @@ pragma solidity ^0.5.10; -import {IBondedECDSAKeep} from "@keep-network/keep-ecdsa/contracts/api/IBondedECDSAKeep.sol"; +import { + IBondedECDSAKeep +} from "@keep-network/keep-ecdsa/contracts/api/IBondedECDSAKeep.sol"; /// @notice Implementation of ECDSAKeep interface used in tests only /// @dev This is a stub used in tests, so we don't have to call actual ECDSAKeep contract ECDSAKeepStub is IBondedECDSAKeep { bytes publicKey; - bool success; + bool success = true; uint256 bondAmount = 10000; // Notification that the keep was requested to sign a digest. - event SignatureRequested( - bytes32 digest - ); + event SignatureRequested(bytes32 digest); // Define fallback function so the contract can accept ether. function() external payable {} + // Functions implemented for IBondedECDSAKeep interface. + function getPublicKey() external view returns (bytes memory) { return publicKey; } - function sign(bytes32 _digest) external { - emit SignatureRequested(_digest); + function checkBondAmount() external view returns (uint256) { + return bondAmount; } - function returnPartialSignerBonds() external payable { - // solium-disable-previous-line no-empty-blocks + function sign(bytes32 _digest) external { + emit SignatureRequested(_digest); } - function distributeETHToMembers() external payable { - // solium-disable-previous-line no-empty-blocks + function distributeETHReward() external payable { + // solium-disable-previous-line no-empty-blocks } function distributeERC20Reward(address _asset, uint256 _value) external { - // solium-disable-previous-line no-empty-blocks + // solium-disable-previous-line no-empty-blocks } - function distributeETHReward() external payable{ - // solium-disable-previous-line no-empty-blocks + function seizeSignerBonds() external { + if (address(this).balance > 0) { + msg.sender.transfer(address(this).balance); + } } - // Functions implemented for IBondedECDSAKeep interface. + function returnPartialSignerBonds() external payable { + // solium-disable-previous-line no-empty-blocks + } function submitSignatureFraud( uint8, @@ -49,26 +55,22 @@ contract ECDSAKeepStub is IBondedECDSAKeep { bytes32, bytes32, bytes calldata - ) external returns (bool){ - return success; - } + ) external returns (bool) { + require(success, "Signature is not fraudulent"); - function checkBondAmount() external view returns (uint256){ - return bondAmount; - } - - function seizeSignerBonds() external { - if (address(this).balance > 0) { - msg.sender.transfer(address(this).balance); - } + return success; } function closeKeep() external { - // solium-disable-previous-line no-empty-blocks + // solium-disable-previous-line no-empty-blocks } // Functions to set data for tests. + function reset() public { + success = true; + } + function setPublicKey(bytes memory _publicKey) public { publicKey = _publicKey; } diff --git a/implementation/package-lock.json b/implementation/package-lock.json index 511273dad..37dd3793a 100644 --- a/implementation/package-lock.json +++ b/implementation/package-lock.json @@ -5290,6 +5290,21 @@ "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", "dev": true }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, "mocha": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/mocha/-/mocha-4.1.0.tgz", @@ -5304,6 +5319,7 @@ "glob": "7.1.2", "growl": "1.10.3", "he": "1.1.1", + "mkdirp": "0.5.1", "supports-color": "4.4.0" } }, @@ -20136,7 +20152,8 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true } } @@ -26625,6 +26642,21 @@ "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", "dev": true }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, "mocha": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/mocha/-/mocha-4.1.0.tgz", @@ -26639,6 +26671,7 @@ "glob": "7.1.2", "growl": "1.10.3", "he": "1.1.1", + "mkdirp": "0.5.1", "supports-color": "4.4.0" } }, diff --git a/implementation/test/DepositFraudTest.js b/implementation/test/DepositFraudTest.js index 2c7cad039..7513849ba 100644 --- a/implementation/test/DepositFraudTest.js +++ b/implementation/test/DepositFraudTest.js @@ -57,6 +57,7 @@ describe("DepositFraud", async function() { beforeEach(async () => { await testDeposit.reset() + await ecdsaKeepStub.reset() await testDeposit.setKeepAddress(ecdsaKeepStub.address) }) @@ -71,7 +72,7 @@ describe("DepositFraud", async function() { const block = await web3.eth.getBlock("latest") const blockTimestamp = block.timestamp fundingProofTimerStart = blockTimestamp - timer.toNumber() - 1 // has elapsed - await ecdsaKeepStub.setSuccess(true) + await testDeposit.setState(states.AWAITING_BTC_FUNDING_PROOF) await ecdsaKeepStub.send(1000000, {from: owner}) @@ -441,7 +442,6 @@ describe("DepositFraud", async function() { before(async () => { await testDeposit.setState(states.ACTIVE) await ecdsaKeepStub.send(1000000, {from: owner}) - await ecdsaKeepStub.setSuccess(true) }) beforeEach(async () => { diff --git a/implementation/test/DepositFundingTest.js b/implementation/test/DepositFundingTest.js index fc32eb86a..162a776b7 100644 --- a/implementation/test/DepositFundingTest.js +++ b/implementation/test/DepositFundingTest.js @@ -75,6 +75,7 @@ describe("DepositFunding", async function() { ) await testDeposit.reset() + await ecdsaKeepStub.reset() await testDeposit.setKeepAddress(ecdsaKeepStub.address) }) diff --git a/implementation/test/DepositLiquidationTest.js b/implementation/test/DepositLiquidationTest.js index ce23a7489..5df2f3b43 100644 --- a/implementation/test/DepositLiquidationTest.js +++ b/implementation/test/DepositLiquidationTest.js @@ -66,6 +66,7 @@ describe("DepositLiquidation", async function() { web3.utils.toBN(testDeposit.address), ) await testDeposit.reset() + await ecdsaKeepStub.reset() await testDeposit.setKeepAddress(ecdsaKeepStub.address) }) diff --git a/implementation/test/DepositRedemptionTest.js b/implementation/test/DepositRedemptionTest.js index f084f8d53..07409f527 100644 --- a/implementation/test/DepositRedemptionTest.js +++ b/implementation/test/DepositRedemptionTest.js @@ -69,6 +69,7 @@ describe("DepositRedemption", async function() { beforeEach(async () => { await testDeposit.reset() + await ecdsaKeepStub.reset() await testDeposit.setKeepAddress(ecdsaKeepStub.address) }) @@ -509,7 +510,6 @@ describe("DepositRedemption", async function() { await tbtcToken.resetAllowance(testDeposit.address, requiredBalance, { from: owner, }) - await ecdsaKeepStub.setSuccess(true) }) afterEach(async () => { @@ -796,7 +796,6 @@ describe("DepositRedemption", async function() { withdrawalRequestTime, prevSighash, ) - await ecdsaKeepStub.setSuccess(true) }) it("approves a new digest for signing, updates the state, and logs RedemptionRequested", async () => { diff --git a/implementation/test/DepositUtilsTest.js b/implementation/test/DepositUtilsTest.js index ef56cefa2..f55ad228b 100644 --- a/implementation/test/DepositUtilsTest.js +++ b/implementation/test/DepositUtilsTest.js @@ -84,7 +84,10 @@ describe("DepositUtils", async function() { fullBtc, {value: funderBondAmount}, ) + }) + beforeEach(async () => { + await ecdsaKeepStub.reset() await testDeposit.setKeepAddress(ecdsaKeepStub.address) }) diff --git a/implementation/test/VendingMachineTest.js b/implementation/test/VendingMachineTest.js index 8a0169713..d73bf505b 100644 --- a/implementation/test/VendingMachineTest.js +++ b/implementation/test/VendingMachineTest.js @@ -35,7 +35,6 @@ describe("VendingMachine", async function() { let tbtcDepositToken let feeRebateToken let testDeposit - let ecdsaKeepStub let assertBalance let tdtId @@ -54,7 +53,6 @@ describe("VendingMachine", async function() { tbtcDepositToken, feeRebateToken, testDeposit, - ecdsaKeepStub, deployed, redemptionScript, fundingScript, @@ -337,7 +335,6 @@ describe("VendingMachine", async function() { await tbtcToken.resetAllowance(vendingMachine.address, requiredBalance, { from: owner, }) - await ecdsaKeepStub.setSuccess(true) await testDeposit.setState(states.ACTIVE) await testDeposit.setUTXOInfo(valueBytes, block.timestamp, outpoint) })