Skip to content

Commit

Permalink
Removed redundant check
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Dec 22, 2023
1 parent db47dbb commit 8f8de02
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 45 deletions.
6 changes: 0 additions & 6 deletions solidity/contracts/bridge/WalletProposalValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ contract WalletProposalValidator {
/// - The target wallets commitment must be submitted,
/// - The target wallets commitment hash must match the target wallets
/// from the proposal,
/// - The source wallet BTC balance must be positive,
/// - The source wallet BTC balance must be equal to or greater than
/// `movingFundsDustThreshold`,
/// - The proposed moving funds transaction fee must be greater than
Expand Down Expand Up @@ -668,11 +667,6 @@ contract WalletProposalValidator {
walletMainUtxo
);

require(
sourceWalletBtcBalance > 0,
"Source wallet BTC balance is zero"
);

require(
sourceWalletBtcBalance >= movingFundsDustThreshold,
"Source wallet BTC balance is below the moving funds dust threshold"
Expand Down
81 changes: 42 additions & 39 deletions solidity/test/bridge/WalletProposalValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,48 @@ describe("WalletProposalValidator", () => {
})

context("when commitment hash matches target wallets", () => {
context("when no main UTXO is passed", () => {
before(async () => {
await createSnapshot()

bridge.wallets.whenCalledWith(walletPubKeyHash).returns({
ecdsaWalletID: HashZero,
// Use zero hash so that the wallet's main UTXO is considered
// not set. This will be interpreted as the wallet having BTC
// balance of zero.
mainUtxoHash: HashZero,
pendingRedemptionsValue: 0,
createdAt: 0,
movingFundsRequestedAt: 0,
closingStartedAt: 0,
pendingMovedFundsSweepRequestsCount: 0,
state: walletState.MovingFunds,
movingFundsTargetWalletsCommitmentHash: targetWalletsHash,
})
})

after(async () => {
bridge.wallets.reset()

await restoreSnapshot()
})

it("should revert", async () => {
await expect(
walletProposalValidator.validateMovingFundsProposal(
{
walletPubKeyHash,
movingFundsTxFee: 0,
targetWallets,
},
NO_MAIN_UTXO
)
).to.be.revertedWith(
"Source wallet BTC balance is below the moving funds dust threshold"
)
})
})

context("when the passed main UTXO is incorrect", () => {
before(async () => {
await createSnapshot()
Expand Down Expand Up @@ -2132,45 +2174,6 @@ describe("WalletProposalValidator", () => {
})

context("when the passed main UTXO is correct", () => {
context("when source wallet BTC balance is zero", () => {
before(async () => {
await createSnapshot()

bridge.wallets.whenCalledWith(walletPubKeyHash).returns({
ecdsaWalletID: HashZero,
// Use zero hash so that the wallet's main is considered not
// set.
mainUtxoHash: HashZero,
pendingRedemptionsValue: 0,
createdAt: 0,
movingFundsRequestedAt: 0,
closingStartedAt: 0,
pendingMovedFundsSweepRequestsCount: 0,
state: walletState.MovingFunds,
movingFundsTargetWalletsCommitmentHash: targetWalletsHash,
})
})

after(async () => {
bridge.wallets.reset()

await restoreSnapshot()
})

it("should revert", async () => {
await expect(
walletProposalValidator.validateMovingFundsProposal(
{
walletPubKeyHash,
movingFundsTxFee: 0,
targetWallets,
},
NO_MAIN_UTXO
)
).to.be.revertedWith("Source wallet BTC balance is zero")
})
})

context(
"when source wallet BTC balance is below dust threshold",
() => {
Expand Down

0 comments on commit 8f8de02

Please sign in to comment.