def test_TestTransactionPushInput(): handle = utils.makeEmptyTransaction() ux = utils.makeUxOut() sha = skycoin.cipher_SHA256() assert skycoin.SKY_coin_UxOut_Hash(ux, sha) == skycoin.SKY_OK r = skycoin.SKY_coin_Transaction_PushInput(handle, sha) assert r == 0 _, count = skycoin.SKY_coin_Transaction_GetInputsCount(handle) assert count == 1 sha1 = skycoin.cipher_SHA256() skycoin.SKY_coin_Transaction_GetInputAt(handle, 0, sha1) assert sha == sha1 skycoin.SKY_coin_Transaction_ResetInputs(handle, 0) for _ in range(utils.MaxUint16): skycoin.SKY_coin_Transaction_PushInput( handle, skycoin.cipher_SHA256()) ux = utils.makeUxOut() assert skycoin.SKY_coin_UxOut_Hash(ux, sha) == skycoin.SKY_OK
def test_TestTransactionHashInner(): handle, tx = utils.makeTransaction() h = skycoin.cipher_SHA256() assert skycoin.SKY_coin_Transaction_HashInner(handle, h) == skycoin.SKY_OK assert h != skycoin.cipher_SHA256() # If tx.In is changed, hash should change handle2, tx2 = utils.copyTransaction(handle) ux = utils.makeUxOut() h = skycoin.cipher_SHA256() h1 = skycoin.cipher_SHA256() assert skycoin.SKY_coin_UxOut_Hash(ux, h) == skycoin.SKY_OK assert skycoin.SKY_coin_Transaction_SetInputAt( handle2, 0, h) == skycoin.SKY_OK assert tx != tx2 assert skycoin.SKY_coin_UxOut_Hash(ux, h1) == skycoin.SKY_OK assert h == h1 assert skycoin.SKY_coin_Transaction_HashInner(handle, h) == skycoin.SKY_OK assert skycoin.SKY_coin_Transaction_HashInner( handle2, h1) == skycoin.SKY_OK assert h != h1 # If tx.Out is changed, hash should change handle2, tx2 = utils.copyTransaction(handle) a = utils.makeAddress() a2 = skycoin.cipher__Address() pOut = skycoin.coin__TransactionOutput() assert skycoin.SKY_coin_Transaction_GetOutputAt( handle2, 0, pOut) == skycoin.SKY_OK pOut.Address = a assert skycoin.SKY_coin_Transaction_SetOutputAt( handle2, 0, pOut) == skycoin.SKY_OK assert tx != tx2 assert skycoin.SKY_coin_Transaction_GetOutputAt( handle2, 0, pOut) == skycoin.SKY_OK assert pOut.Address == a sha1 = skycoin.cipher_SHA256() sha2 = skycoin.cipher_SHA256() assert skycoin.SKY_coin_Transaction_HashInner( handle, sha1) == skycoin.SKY_OK assert skycoin.SKY_coin_Transaction_HashInner( handle2, sha2) == skycoin.SKY_OK assert sha1 != sha2 # If tx.Head is changed, hash should not change handle2, tx2 = utils.copyTransaction(handle) sig = skycoin.cipher_Sig() assert skycoin.SKY_coin_Transaction_PushSignature( handle, sig) == skycoin.SKY_OK sha1 = skycoin.cipher_SHA256() sha2 = skycoin.cipher_SHA256() assert skycoin.SKY_coin_Transaction_HashInner( handle, sha1) == skycoin.SKY_OK assert skycoin.SKY_coin_Transaction_HashInner( handle2, sha2) == skycoin.SKY_OK assert sha1 == sha2