nwaku/tests/v2/test_waku_swap_contracts.nim
Oskar Thorén b730d79438
Waku Swap: sign and send cheque (#386)
* fix balance test

* move waku swap contracts into own module

* Move more to separate waku swap contracts

* move erc20address

* Improve cmd/task util

* fix redeem part too

* sign cheque hardcode

* add signature field, send cheque

* echo->debug

* disable waku swap test

it calls contracts, which isnt integrated
2021-02-23 13:15:06 +08:00

64 lines
1.8 KiB
Nim

# Tests of Swap contracts via external module
#
import
std/[unittest, options, tables, sets, osproc, strutils, strformat, json],
chronicles,
../test_helpers, ./utils,
../../waku/v2/protocol/waku_swap/waku_swap_contracts
procSuite "Basic balance test":
var aliceSwapAddress = ""
var signature = ""
var erc20address = ""
test "Get pwd of swap module":
let (output, errC) = osproc.execCmdEx("(cd ../swap-contracts-module && pwd)")
debug "output", output
check:
contains(output, "swap-contracts-module")
test "Get balance from running node":
# NOTE: This corresponds to the first default account in Hardhat
let balance = waku_swap_contracts.getBalance("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
check:
contains(balance, "ETH")
test "Setup Swap":
let json = waku_swap_contracts.setupSwap()
var aliceAddress = json["aliceAddress"].getStr()
aliceSwapAddress = json["aliceSwapAddress"].getStr()
erc20address = json["erc20address"].getStr()
debug "erc20address", erc20address
debug "json", json
# Contains default Alice account
check:
contains(aliceAddress, "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
test "Sign Cheque":
signature = waku_swap_contracts.signCheque(aliceSwapAddress)
check:
contains(signature, "0x")
test "Get ERC20 Balances":
let json = getERC20Balances(erc20address)
check:
json["bobBalance"].getInt() == 10000
test "Redeem cheque and check balance":
let json = waku_swap_contracts.redeemCheque(aliceSwapAddress, signature)
var resp = json["resp"].getStr()
debug "json", json
debug "Get balances"
let json2 = getERC20Balances(erc20address)
debug "json", json2
# Balance for Bob has now increased
check:
json2["bobBalance"].getInt() == 10500