diff --git a/dex-it-common/src/main/scala/com/wavesplatform/dex/it/api/node/NodeApiExtensions.scala b/dex-it-common/src/main/scala/com/wavesplatform/dex/it/api/node/NodeApiExtensions.scala index 3771d76a07..ef6b1d9f5c 100644 --- a/dex-it-common/src/main/scala/com/wavesplatform/dex/it/api/node/NodeApiExtensions.scala +++ b/dex-it-common/src/main/scala/com/wavesplatform/dex/it/api/node/NodeApiExtensions.scala @@ -7,6 +7,8 @@ trait NodeApiExtensions { this: HasWavesNode => + protected def broadcast(tx: Transaction): Unit = wavesNode1.api broadcast tx + protected def broadcastAndAwait(txs: Transaction*): Unit = broadcastAndAwait(wavesNode1.api, txs: _*) protected def broadcastAndAwait(wavesNodeApi: NodeApi[Id], txs: Transaction*): Unit = { diff --git a/waves-integration-it/src/test/scala/com/wavesplatform/dex/grpc/integration/clients/CombinedWavesBlockchainClientTestSuite.scala b/waves-integration-it/src/test/scala/com/wavesplatform/dex/grpc/integration/clients/CombinedWavesBlockchainClientTestSuite.scala index 2aadd6acf4..0cfdb682a9 100644 --- a/waves-integration-it/src/test/scala/com/wavesplatform/dex/grpc/integration/clients/CombinedWavesBlockchainClientTestSuite.scala +++ b/waves-integration-it/src/test/scala/com/wavesplatform/dex/grpc/integration/clients/CombinedWavesBlockchainClientTestSuite.scala @@ -299,76 +299,136 @@ class CombinedWavesBlockchainClientTestSuite extends IntegrationSuiteBase with H "partialBalancesSnapshot" in { val leaseAmount = 1.waves - val leaseTx = mkLease(bob, alice, leaseAmount) - val balanceBefore = wavesNode1.api.balance(bob, Waves) - wavesNode1.api.broadcast(leaseTx) - - wait(client.partialBalancesSnapshot(bob, Set(Waves, randomIssuedAsset))) should { - // leaseTx haven't been added to UTX yet - matchTo(AddressBalanceUpdates( - regular = Map(Waves -> balanceBefore), - outgoingLeasing = Some(0L), - pessimisticCorrection = Map.empty - )) or - // not confirmed - matchTo(AddressBalanceUpdates( - regular = Map(Waves -> balanceBefore), - outgoingLeasing = Some(0L), - pessimisticCorrection = Map(Waves -> -(leaseAmount + leasingFee)) - )) or - // confirmed - matchTo(AddressBalanceUpdates( - regular = Map(Waves -> (balanceBefore - leaseAmount - leasingFee)), - outgoingLeasing = Some(leaseAmount), - pessimisticCorrection = Map.empty - )) + + def notInUtx(balanceBefore: Long) = matchTo(AddressBalanceUpdates( + regular = Map(Waves -> balanceBefore), + outgoingLeasing = Some(0L), + pessimisticCorrection = Map.empty + )) + + def notConfirmed(balanceBefore: Long) = matchTo(AddressBalanceUpdates( + regular = Map(Waves -> balanceBefore), + outgoingLeasing = Some(0L), + pessimisticCorrection = Map(Waves -> -(leaseAmount + leasingFee)) + )) + + def confirmed(balanceBefore: Long) = matchTo(AddressBalanceUpdates( + regular = Map(Waves -> (balanceBefore - leasingFee)), + outgoingLeasing = Some(leaseAmount), + pessimisticCorrection = Map(Waves -> 0) + )) + + withClue("transaction is not in UTX") { + val balance1 = wavesNode1.api.balance(bob, Waves) + val leaseTx = mkLease(bob, alice, leaseAmount) + broadcast(leaseTx) + + wait(client.partialBalancesSnapshot(bob, Set(Waves, randomIssuedAsset))) should { + notInUtx(balance1) or notConfirmed(balance1) or confirmed(balance1) + } + + wavesNode1.api.waitForTransaction(leaseTx) + broadcastAndAwait(mkLeaseCancel(bob, leaseTx.id())) } - wavesNode1.api.waitForTransaction(leaseTx) - broadcastAndAwait(mkLeaseCancel(bob, leaseTx.id())) + withClue("transaction is in UTX but not confirmed") { + val balance1 = wavesNode1.api.balance(bob, Waves) + val leaseTx = mkLease(bob, alice, leaseAmount) + broadcast(leaseTx) + + wait(client.partialBalancesSnapshot(bob, Set(Waves, randomIssuedAsset))) should { + notConfirmed(balance1) or confirmed(balance1) + } + + wavesNode1.api.waitForTransaction(leaseTx) + broadcastAndAwait(mkLeaseCancel(bob, leaseTx.id())) + } + + withClue("transaction is confirmed") { + val balance1 = wavesNode1.api.balance(bob, Waves) + val leaseTx = mkLease(bob, alice, leaseAmount) + + broadcastAndAwait(leaseTx) + wavesNode1.api.waitForHeightArise() + + wait(client.partialBalancesSnapshot(bob, Set(Waves, randomIssuedAsset))) should { + confirmed(balance1) + } + + broadcastAndAwait(mkLeaseCancel(bob, leaseTx.id())) + } } "fullBalancesSnapshot" in { - val carol = mkKeyPair("carol") + val acc1 = mkKeyPair("acc1") + val acc2 = mkKeyPair("acc2") + val acc3 = mkKeyPair("acc3") + val leaseAmount = 1.waves broadcastAndAwait( - mkTransfer(bob, carol, 10.waves, Waves), - mkTransfer(alice, carol, 1.usd, usd), - mkTransfer(bob, carol, 1.btc, btc) + mkTransfer(bob, acc1, 10.waves, Waves), + mkTransfer(alice, acc1, 1.usd, usd), + mkTransfer(bob, acc1, 1.btc, btc), + mkTransfer(bob, acc2, 10.waves, Waves), + mkTransfer(alice, acc2, 1.usd, usd), + mkTransfer(bob, acc2, 1.btc, btc), + mkTransfer(bob, acc3, 10.waves, Waves), + mkTransfer(alice, acc3, 1.usd, usd), + mkTransfer(bob, acc3, 1.btc, btc) ) - val leaseAmount = 1.waves - val leaseTx = mkLease(carol, bob, leaseAmount) - wavesNode1.api.broadcast(leaseTx) - - wait(client.fullBalancesSnapshot(carol, Set(btc))) should { - // leaseTx haven't been added to UTX yet - matchTo(AddressBalanceUpdates( - regular = Map[Asset, Long]( - Waves -> 10.waves, - usd -> 1.usd - ), - outgoingLeasing = Some(0L), - pessimisticCorrection = Map.empty - )) or - // not confirmed - matchTo(AddressBalanceUpdates( - regular = Map[Asset, Long]( - Waves -> 10.waves, - usd -> 1.usd - ), - outgoingLeasing = Some(0L), - pessimisticCorrection = Map(Waves -> -(leaseAmount + leasingFee)) - )) or - // confirmed - matchTo(AddressBalanceUpdates( - regular = Map[Asset, Long]( - Waves -> (10.waves - leaseAmount - leasingFee), - usd -> 1.usd - ), - outgoingLeasing = Some(leaseAmount), - pessimisticCorrection = Map.empty - )) + def notInUtx() = matchTo(AddressBalanceUpdates( + regular = Map[Asset, Long]( + Waves -> 10.waves, + usd -> 1.usd + ), + outgoingLeasing = Some(0L), + pessimisticCorrection = Map.empty + )) + + def notConfirmed() = matchTo(AddressBalanceUpdates( + regular = Map[Asset, Long]( + Waves -> 10.waves, + usd -> 1.usd + ), + outgoingLeasing = Some(0L), + pessimisticCorrection = Map(Waves -> -(leaseAmount + leasingFee)) + )) + + def confirmed() = matchTo(AddressBalanceUpdates( + regular = Map[Asset, Long]( + Waves -> (10.waves - leasingFee), + usd -> 1.usd + ), + outgoingLeasing = Some(leaseAmount), + pessimisticCorrection = Map(Waves -> 0) + )) + + withClue("transaction is not in UTX") { + broadcast(mkLease(acc1, bob, leaseAmount)) + + wait(client.fullBalancesSnapshot(acc1, Set(btc))) should { + notInUtx() or notConfirmed() or confirmed() + } + } + + withClue("transaction is in UTX but not confirmed") { + broadcast(mkLease(acc2, bob, leaseAmount)) + + wait(client.fullBalancesSnapshot(acc2, Set(btc))) should { + notConfirmed() or confirmed() + } + } + + withClue("transaction is confirmed") { + broadcastAndAwait(mkLease(acc3, bob, leaseAmount)) + wavesNode1.api.waitForHeightArise() + + eventually { + wait(client.fullBalancesSnapshot(acc3, Set(btc))) should { + confirmed() + } + } } }