2021-04-14 14:07:49 +00:00
|
|
|
import std/unittest
|
2021-08-30 19:25:20 +00:00
|
|
|
|
|
|
|
import pkg/dagger/stores
|
2021-04-14 14:07:49 +00:00
|
|
|
import ../../examples
|
|
|
|
|
|
|
|
suite "engine payments":
|
|
|
|
|
2021-05-10 14:21:47 +00:00
|
|
|
let address = EthAddress.example
|
2021-05-10 11:47:15 +00:00
|
|
|
let amount = 42.u256
|
2021-04-14 14:07:49 +00:00
|
|
|
|
2021-04-19 14:37:38 +00:00
|
|
|
var wallet: WalletRef
|
2021-08-30 19:25:20 +00:00
|
|
|
var peer: BlockExcPeerCtx
|
2021-04-14 14:07:49 +00:00
|
|
|
|
|
|
|
setup:
|
2021-04-19 14:37:38 +00:00
|
|
|
wallet = WalletRef.example
|
2021-08-30 19:25:20 +00:00
|
|
|
peer = BlockExcPeerCtx.example
|
2021-05-10 14:21:47 +00:00
|
|
|
peer.account = Account(address: address).some
|
2021-04-14 14:07:49 +00:00
|
|
|
|
2021-05-10 11:47:15 +00:00
|
|
|
test "pays for received blocks":
|
|
|
|
let payment = !wallet.pay(peer, amount)
|
2021-04-22 08:11:24 +00:00
|
|
|
let balances = payment.state.outcome.balances(Asset)
|
2021-05-10 14:21:47 +00:00
|
|
|
let destination = address.toDestination
|
2021-05-10 11:47:15 +00:00
|
|
|
check !balances[destination] == amount
|
2021-04-14 14:07:49 +00:00
|
|
|
|
2021-05-10 14:21:47 +00:00
|
|
|
test "no payment when no account is set":
|
|
|
|
peer.account = Account.none
|
2021-05-10 11:47:15 +00:00
|
|
|
check wallet.pay(peer, amount).isFailure
|
2021-04-14 14:07:49 +00:00
|
|
|
|
|
|
|
test "uses same channel for consecutive payments":
|
2021-05-10 11:47:15 +00:00
|
|
|
let payment1, payment2 = wallet.pay(peer, amount)
|
2021-04-14 14:07:49 +00:00
|
|
|
let channel1 = payment1.?state.?channel.?getChannelId
|
|
|
|
let channel2 = payment2.?state.?channel.?getChannelId
|
|
|
|
check channel1 == channel2
|