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

Commit

Permalink
Merge branch 'master' into base-liq-percent
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadowfiend authored Mar 24, 2020
2 parents b46d498 + f77577c commit 8ef9c4b
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 36 deletions.
3 changes: 2 additions & 1 deletion implementation/contracts/deposit/DepositUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
56 changes: 29 additions & 27 deletions implementation/contracts/test/keep/ECDSAKeepStub.sol
Original file line number Diff line number Diff line change
@@ -1,74 +1,76 @@
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,
bytes32,
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;
}
Expand Down
35 changes: 34 additions & 1 deletion implementation/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions implementation/test/DepositFraudTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe("DepositFraud", async function() {

beforeEach(async () => {
await testDeposit.reset()
await ecdsaKeepStub.reset()
await testDeposit.setKeepAddress(ecdsaKeepStub.address)
})

Expand All @@ -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})
Expand Down Expand Up @@ -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 () => {
Expand Down
1 change: 1 addition & 0 deletions implementation/test/DepositFundingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe("DepositFunding", async function() {
)

await testDeposit.reset()
await ecdsaKeepStub.reset()
await testDeposit.setKeepAddress(ecdsaKeepStub.address)
})

Expand Down
1 change: 1 addition & 0 deletions implementation/test/DepositLiquidationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe("DepositLiquidation", async function() {
web3.utils.toBN(testDeposit.address),
)
await testDeposit.reset()
await ecdsaKeepStub.reset()
await testDeposit.setKeepAddress(ecdsaKeepStub.address)
})

Expand Down
3 changes: 1 addition & 2 deletions implementation/test/DepositRedemptionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe("DepositRedemption", async function() {

beforeEach(async () => {
await testDeposit.reset()
await ecdsaKeepStub.reset()
await testDeposit.setKeepAddress(ecdsaKeepStub.address)
})

Expand Down Expand Up @@ -509,7 +510,6 @@ describe("DepositRedemption", async function() {
await tbtcToken.resetAllowance(testDeposit.address, requiredBalance, {
from: owner,
})
await ecdsaKeepStub.setSuccess(true)
})

afterEach(async () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
3 changes: 3 additions & 0 deletions implementation/test/DepositUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ describe("DepositUtils", async function() {
fullBtc,
{value: funderBondAmount},
)
})

beforeEach(async () => {
await ecdsaKeepStub.reset()
await testDeposit.setKeepAddress(ecdsaKeepStub.address)
})

Expand Down
3 changes: 0 additions & 3 deletions implementation/test/VendingMachineTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe("VendingMachine", async function() {
let tbtcDepositToken
let feeRebateToken
let testDeposit
let ecdsaKeepStub

let assertBalance
let tdtId
Expand All @@ -54,7 +53,6 @@ describe("VendingMachine", async function() {
tbtcDepositToken,
feeRebateToken,
testDeposit,
ecdsaKeepStub,
deployed,
redemptionScript,
fundingScript,
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 8ef9c4b

Please sign in to comment.