Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Dec 14, 2023
1 parent 5a021e8 commit 3a28bc5
Showing 1 changed file with 174 additions and 1 deletion.
175 changes: 174 additions & 1 deletion solidity/test/bridge/WalletProposalValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,180 @@ describe("WalletProposalValidator", () => {
})

context("when wallet's state is MovingFunds", () => {
// TODO: Implement
context("when the wallet has pending redemptions", () => {
before(async () => {
await createSnapshot()

bridge.wallets.whenCalledWith(walletPubKeyHash).returns({
ecdsaWalletID,
mainUtxoHash: HashZero,
pendingRedemptionsValue: 10000, // Make the value positive.
createdAt: 0,
movingFundsRequestedAt: 0,
closingStartedAt: 0,
pendingMovedFundsSweepRequestsCount: 0,
state: walletState.MovingFunds,
movingFundsTargetWalletsCommitmentHash: HashZero,
})
})

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 has pending redemptions")
})
})

context("when the wallet does not have pending redemptions", () => {
context(
"when the wallet has pending moved funds sweep requests",
() => {
before(async () => {
await createSnapshot()

bridge.wallets.whenCalledWith(walletPubKeyHash).returns({
ecdsaWalletID,
mainUtxoHash: HashZero,
pendingRedemptionsValue: 0,
createdAt: 0,
movingFundsRequestedAt: 0,
closingStartedAt: 0,
pendingMovedFundsSweepRequestsCount: 1, // Make the value positive.
state: walletState.MovingFunds,
movingFundsTargetWalletsCommitmentHash: HashZero,
})
})

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 has pending moved funds sweep requests"
)
})
}
)

context(
"when the wallet does not have pending moved funds sweep requests",
() => {
context("when the provided main UTXO is invalid", () => {
before(async () => {
await createSnapshot()

bridge.wallets.whenCalledWith(walletPubKeyHash).returns({
ecdsaWalletID,
mainUtxoHash:
// Use any non-zero hash to indicate the wallet has a main UTXO.
"0x1111111111111111111111111111111111111111111111111111111111111111",
pendingRedemptionsValue: 0,
createdAt: 0,
movingFundsRequestedAt: 0,
closingStartedAt: 0,
pendingMovedFundsSweepRequestsCount: 0,
state: walletState.MovingFunds,
movingFundsTargetWalletsCommitmentHash: HashZero,
})
})

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

await restoreSnapshot()
})

it("should revert", async () => {
await expect(
walletProposalValidator.validateMovingFundsProposal(
{
walletPubKeyHash,
movingFundsTxFee: 0,
targetWallets: [],
},
{
txHash:
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
txOutputIndex: 0,
txOutputValue: 1000,
}
)
).to.be.revertedWith("Invalid wallet main UTXO data")
})
})

context("when the provided main UTXO is valid", () => {
context("when the wallet's balance is zero", () => {
before(async () => {
await createSnapshot()

bridge.wallets.whenCalledWith(walletPubKeyHash).returns({
ecdsaWalletID,
// 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: HashZero,
})
})

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 the wallet's balance is positive", () => {
// TODO: Implement.
})
})
}
)
})
})
})

Expand Down

0 comments on commit 3a28bc5

Please sign in to comment.