Merge pull request #1219 from tonymorony/FSM

Adjusted heir tests for heirCC JSON changes and added heirfund tokens case check
This commit is contained in:
jl777
2019-01-28 02:18:42 -11:00
committed by GitHub
2 changed files with 78 additions and 19 deletions

View File

@@ -26,6 +26,14 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework):
rpc = self.nodes[0]
rpc1 = self.nodes[1]
# checking channelsaddress call
result = rpc.channelsaddress(self.pubkey)
assert_success(result)
# test that additional CCaddress key is returned
for x in ['myCCaddress', 'ChannelsCCaddress', 'Channelsmarker', 'myaddress', 'CCaddress']:
assert_equal(result[x][0], 'R')
# getting empty channels list
result = rpc.channelslist()
assert_equal(len(result), 2)
@@ -143,7 +151,7 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework):
refund_txid = self.send_and_mine(result["hex"], rpc)
assert refund_txid, "got txid"
# TODO: check if it refunded to opener address
# checking if it refunded to opener address
raw_transaction = rpc.getrawtransaction(refund_txid, 1)
result = raw_transaction["vout"][2]["valueSat"]

View File

@@ -34,21 +34,18 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework):
# getting empty heir list
result = rpc.heirlist()
assert_equal(len(result), 1)
assert_success(result)
assert_equal(result, [])
# valid heirfund case with coins
result = rpc.heirfund("0", "1000", "UNITHEIR", self.pubkey1, "10")
result = rpc.heirfund("0", "1000", "UNITHEIR", self.pubkey1, "10", "TESTMEMO")
assert_success(result)
heir_fund_txid = self.send_and_mine(result["hextx"], rpc)
heir_fund_txid = self.send_and_mine(result["hex"], rpc)
assert heir_fund_txid, "got heir funding txid"
# heir fund txid should be in heirlist now
result = rpc.heirlist()
assert_equal(len(result), 2)
assert_success(result)
assert_equal(result["fundingtxid"], heir_fund_txid)
assert_equal(result, [heir_fund_txid])
# checking heirinfo
result = rpc.heirinfo(heir_fund_txid)
@@ -57,20 +54,20 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework):
assert_equal(result["name"], "UNITHEIR")
assert_equal(result["owner"], self.pubkey)
assert_equal(result["heir"], self.pubkey1)
assert_equal(result["funding total in coins"], "1000.00000000")
assert_equal(result["funding available in coins"], "1000.00000000")
assert_equal(result["inactivity time setting, sec"], "10")
assert_equal(result["spending allowed for the heir"], "false")
# TODO: heirlist keys are duplicating now
assert_equal(result["memo"], "TESTMEMO")
assert_equal(result["lifetime"], "1000.00000000")
assert_equal(result["type"], "coins")
assert_equal(result["InactivityTimeSetting"], "10")
assert_equal(result["InactivityTime"], "0")
assert_equal(result["IsHeirSpendingAllowed"], "false")
# waiting for 11 seconds to be sure that needed time passed for heir claiming
time.sleep(11)
rpc.generate(1)
self.sync_all()
result = rpc.heirinfo(heir_fund_txid)
assert_equal(result["funding available in coins"], "1000.00000000")
assert_equal(result["spending allowed for the heir"], "true")
assert_equal(result["lifetime"], "1000.00000000")
assert_equal(result["IsHeirSpendingAllowed"], "true")
# have to check that second node have coins to cover txfee at least
rpc.sendtoaddress(rpc1.getnewaddress(), 1)
@@ -84,7 +81,7 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework):
result = rpc1.heirclaim("0", "1000", heir_fund_txid)
assert_success(result)
heir_claim_txid = self.send_and_mine(result["hextx"], rpc1)
heir_claim_txid = self.send_and_mine(result["hex"], rpc1)
assert heir_claim_txid, "got claim txid"
# balance of second node after heirclaim should increase for 1000 coins - txfees
@@ -96,9 +93,63 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework):
# no more funds should be available for claiming
result = rpc.heirinfo(heir_fund_txid)
assert_equal(result["funding available in coins"], "0.00000000")
assert_equal(result["lifetime"], "1000.00000000")
assert_equal(result["available"], "0.00000000")
# TODO: valid heirfund case with tokens
# creating tokens which we put to heir contract
token_hex = rpc.tokencreate("TEST", "1", "TESTING")
token_txid = self.send_and_mine(token_hex["hex"], rpc)
assert token_txid, "got token txid"
# checking possesion over the tokens and balance
result = rpc.tokenbalance(token_txid, self.pubkey)["balance"]
assert_equal(result, 100000000)
# valid heir case with tokens
token_heir_hex = rpc.heirfund("0", "100000000", "UNITHEIR", self.pubkey1, "10", "TESTMEMO", token_txid)
token_heir_txid = self.send_and_mine(token_heir_hex["hex"], rpc)
assert token_heir_txid, "got txid of heirfund with tokens"
self.sync_all()
# checking heirinfo
result = rpc.heirinfo(token_heir_txid)
assert_success(result)
assert_equal(result["fundingtxid"], token_heir_txid)
assert_equal(result["name"], "UNITHEIR")
assert_equal(result["owner"], self.pubkey)
assert_equal(result["heir"], self.pubkey1)
assert_equal(result["lifetime"], "100000000")
assert_equal(result["type"], "tokens")
assert_equal(result["InactivityTimeSetting"], "10")
assert_equal(result["InactivityTime"], "0")
assert_equal(result["IsHeirSpendingAllowed"], "false")
# waiting for 11 seconds to be sure that needed time passed for heir claiming
time.sleep(11)
rpc.generate(1)
self.sync_all()
result = rpc.heirinfo(token_heir_txid)
assert_equal(result["lifetime"], "100000000")
assert_equal(result["IsHeirSpendingAllowed"], "true")
# let's claim whole heir sum from second node
result = rpc1.heirclaim("0", "100000000", token_heir_txid)
assert_success(result)
heir_tokens_claim_txid = self.send_and_mine(result["hex"], rpc1)
assert heir_tokens_claim_txid, "got claim txid"
# claiming node should have correct token balance now
result = rpc1.tokenbalance(token_txid, self.pubkey1)["balance"]
assert_equal(result, 100000000)
self.sync_all()
# no more funds should be available for claiming
result = rpc.heirinfo(token_heir_txid)
assert_equal(result["lifetime"], "100000000")
assert_equal(result["available"], "0")
def run_test(self):
print("Mining blocks...")