2018-05-16 16:29:44 +02:00
|
|
|
import unittest
|
|
|
|
|
2018-05-18 10:53:32 +02:00
|
|
|
from lbrynet.daemon.Daemon import arrange_results
|
2018-05-16 16:29:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ClaimsComparatorTest(unittest.TestCase):
|
2018-05-18 10:53:32 +02:00
|
|
|
def test_arrange_results_when_sorted_by_claim_id(self):
|
|
|
|
self.run_test(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "fdsafa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res",
|
|
|
|
"claim_id": "aaa",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "w5tv8uorgt"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res",
|
|
|
|
"claim_id": "bbb",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res",
|
|
|
|
"claim_id": "aaa",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "w5tv8uorgt"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res",
|
|
|
|
"claim_id": "bbb",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "fdsafa"
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_arrange_results_when_sorted_by_height(self):
|
|
|
|
self.run_test(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 3,
|
|
|
|
"name": "res",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 2,
|
|
|
|
"name": "res",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"height": 1,
|
|
|
|
"name": "res",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"height": 2,
|
|
|
|
"name": "res",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"height": 3,
|
|
|
|
"name": "res",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_arrange_results_when_sorted_by_name(self):
|
|
|
|
self.run_test(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res1",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res3",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res2",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res1",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res2",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res3",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 0,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_arrange_results_when_sort_by_outpoint(self):
|
|
|
|
self.run_test(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res1",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 2,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res1",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 1,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res1",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 3,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res1",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 1,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res1",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 2,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"height": 1,
|
|
|
|
"name": "res1",
|
|
|
|
"claim_id": "ccc",
|
|
|
|
"nout": 3,
|
|
|
|
"txid": "aecfaewcfa"
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
def run_test(self, results, expected):
|
|
|
|
data = {'result': results}
|
|
|
|
|
|
|
|
claims = arrange_results([data])
|
|
|
|
claim = claims[0]
|
|
|
|
actual = claim['result']
|
|
|
|
|
|
|
|
self.assertEqual(expected, actual)
|
2018-05-16 16:29:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|