def equalTransactions(handle1, handle2): err, size1 = skycoin.SKY_coin_Transactions_Length(handle1) assert err == skycoin.SKY_OK err, size2 = skycoin.SKY_coin_Transactions_Length(handle2) assert err == skycoin.SKY_OK if size1 != size2: return 1 for i in range(int(size1 - 1)): err, tx1 = skycoin.SKY_coin_Transactions_GetAt(handle1, i) assert err == skycoin.SKY_OK err, tx2 = skycoin.SKY_coin_Transactions_GetAt(handle2, i) assert err == skycoin.SKY_OK err, tx1_obj = skycoin.SKY_coin_GetTransactionObject(tx1) assert err == skycoin.SKY_OK err, tx2_obj = skycoin.SKY_coin_GetTransactionObject(tx2) assert err == skycoin.SKY_OK assert tx1_obj == tx2_obj i += 1 return 0
def test_TestTransactionsHashes(): handle = utils.makeTransactions(4) err, hashes = skycoin.SKY_coin_Transactions_Hashes(handle) assert err == skycoin.SKY_OK len_hashes = len(hashes) assert len_hashes == 4 for i in range(len_hashes): err, tx = skycoin.SKY_coin_Transactions_GetAt(handle, i) assert err == skycoin.SKY_OK h = skycoin.cipher_SHA256() assert skycoin.SKY_coin_Transaction_Hash(tx, h) == skycoin.SKY_OK assert h == hashes[i] i += 1
def test_TestTransactionsSize(): handle = utils.makeTransactions(10) size = 0 for i in range(10): err, tx = skycoin.SKY_coin_Transactions_GetAt(handle, i) assert err == skycoin.SKY_OK err, b = skycoin.SKY_coin_Transaction_Serialize(tx) size += len(b) i += 1 assert size != 0 err, sizetx = skycoin.SKY_coin_Transactions_Size(handle) assert err == skycoin.SKY_OK assert sizetx == size
def test_TestTransactionsTruncateBytesTo(): handles = utils.makeTransactions(10) trunc = 0 for i in range(5): err, handle = skycoin.SKY_coin_Transactions_GetAt(handles, i) assert err == skycoin.SKY_OK err, count = skycoin.SKY_coin_Transaction_Size(handle) assert err == skycoin.SKY_OK trunc += count i += 1 # Trucating halfway err, tnxs2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc) assert err == skycoin.SKY_OK err, len_tnxs2 = skycoin.SKY_coin_Transactions_Length(tnxs2) assert err == skycoin.SKY_OK assert len_tnxs2 == 5 err, count = skycoin.SKY_coin_Transactions_Size(tnxs2) assert err == skycoin.SKY_OK assert count == trunc # Stepping into next boundary has same cutoff, must exceed trunc += 1 err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc) assert err == skycoin.SKY_OK err, count = skycoin.SKY_coin_Transactions_Length(tnxs2) assert err == skycoin.SKY_OK assert count == 5 err, count = skycoin.SKY_coin_Transactions_Size(tnxs2) assert err == skycoin.SKY_OK assert count == int(trunc - 1) # Moving to 1 before next level err, tnxs_5 = skycoin.SKY_coin_Transactions_GetAt(handles, 5) assert err == skycoin.SKY_OK err, count = skycoin.SKY_coin_Transaction_Size(tnxs_5) assert err == skycoin.SKY_OK trunc += int(count - 2) err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc) assert err == skycoin.SKY_OK err, count = skycoin.SKY_coin_Transactions_Length(txns2) assert err == skycoin.SKY_OK assert count == 5 err, count = skycoin.SKY_coin_Transactions_Size(txns2) assert err == skycoin.SKY_OK err, count_tnxs5 = skycoin.SKY_coin_Transaction_Size(tnxs_5) assert err == skycoin.SKY_OK assert int(trunc - count_tnxs5 + 1) == count # Moving to next level trunc += 1 err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc) assert err == skycoin.SKY_OK err, count = skycoin.SKY_coin_Transactions_Length(txns2) assert err == skycoin.SKY_OK assert count == 6 err, count = skycoin.SKY_coin_Transactions_Size(txns2) assert err == skycoin.SKY_OK assert count == trunc # Truncating to full available amt err, trunc = skycoin.SKY_coin_Transactions_Size(handles) assert err == skycoin.SKY_OK err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc) assert err == skycoin.SKY_OK assert err == skycoin.SKY_OK err, count = skycoin.SKY_coin_Transactions_Size(txns2) assert err == skycoin.SKY_OK assert count == trunc assert utils.equalTransactions(handles, txns2) == skycoin.SKY_OK # Truncating over amount trunc += 1 err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc) assert utils.equalTransactions(handles, txns2) == skycoin.SKY_OK err, count = skycoin.SKY_coin_Transactions_Size(handles) assert err == skycoin.SKY_OK assert count == int(trunc - 1) # Truncating to 0 trunc = 0 err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, 0) assert err == skycoin.SKY_OK err, count = skycoin.SKY_coin_Transactions_Length(txns2) assert err == skycoin.SKY_OK assert count == 0 err, count = skycoin.SKY_coin_Transactions_Size(txns2) assert err == skycoin.SKY_OK assert count == trunc