Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Danil Lugovskoi <[email protected]>
  • Loading branch information
Deniallugo committed Sep 14, 2022
1 parent c419314 commit 24f1e10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 8 additions & 8 deletions core/lib/storage/src/tests/withdrawals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn test_finalizing(mut storage: StorageProcessor<'_>) -> QueryResult<()> {
token_id: Default::default(),
recipient,
amount: U256::from(5u8),
withdrawal_type: WithdrawalType::ForcedExit,
withdrawal_type: WithdrawalType::Withdrawal,
log_index: 2,
},
WithdrawalPendingEvent {
Expand All @@ -54,8 +54,8 @@ async fn test_finalizing(mut storage: StorageProcessor<'_>) -> QueryResult<()> {
storage
.withdrawals_schema()
.finalize_withdrawal(&WithdrawalEvent {
block_number: 11,
log_index: 0,
block_number: 10,
log_index: 4,
token_id: Default::default(),
recipient,
amount: U256::from(2u8),
Expand All @@ -74,8 +74,8 @@ async fn test_finalizing(mut storage: StorageProcessor<'_>) -> QueryResult<()> {
storage
.withdrawals_schema()
.finalize_withdrawal(&WithdrawalEvent {
block_number: 11,
log_index: 1,
block_number: 10,
log_index: 5,
token_id: Default::default(),
recipient,
amount: U256::from(8u8),
Expand Down Expand Up @@ -110,17 +110,17 @@ async fn test_finalizing(mut storage: StorageProcessor<'_>) -> QueryResult<()> {

assert_eq!(withdrawals.len(), 2);
assert_eq!(withdrawals[0].withdrawal_type, WithdrawalType::ForcedExit);
assert_eq!(withdrawals[1].withdrawal_type, WithdrawalType::ForcedExit);
assert_eq!(withdrawals[1].withdrawal_type, WithdrawalType::Withdrawal);
// Do not process the finalize withdrawal twice
storage
.withdrawals_schema()
.finalize_withdrawal(&WithdrawalEvent {
block_number: 11,
log_index: 0,
log_index: 2,
token_id: Default::default(),
recipient,
amount: U256::from(10u8),
tx_hash: withdrawal_tx_hash_2,
tx_hash: withdrawal_tx_hash_3,
})
.await?;
let result: Option<i64> = sqlx::query_scalar!(
Expand Down
9 changes: 8 additions & 1 deletion core/lib/storage/src/withdrawals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,15 @@ impl<'a, 'c> WithdrawalsSchema<'a, 'c> {
.execute(transaction.conn())
.await?;
amount += charged_amount;
if amount >= withdrawal_amount {
if amount == withdrawal_amount {
break;
}
assert!(
amount < withdrawal_amount,
"Amount should never be greater than withdrawal amount {:?} {:?}",
amount,
withdrawal_amount
);
}
transaction.commit().await?;

Expand All @@ -138,6 +144,7 @@ impl<'a, 'c> WithdrawalsSchema<'a, 'c> {
INNER JOIN withdrawals \
ON finalized_withdrawals.pending_withdrawals_id = withdrawals.id \
WHERE finalized_withdrawals.tx_hash = $1\
ORDER BY withdrawals.tx_log_index
",
tx_hash.as_bytes()
)
Expand Down

0 comments on commit 24f1e10

Please sign in to comment.