public void makeTransactionFromUxOut(coin__UxOut ux, cipher_SecKey s, SWIGTYPE_p_Transaction__Handle handle, coin__Transaction ptx)
        {
            handle = makeEmptyTransaction();
            var h = new cipher_SHA256();

            Assert.AreEqual(skycoin.skycoin.SKY_cipher_SecKey_Verify(s), skycoin.skycoin.SKY_OK);
            var err = skycoin.skycoin.SKY_coin_UxOut_Hash(ux, h);

            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
            var r = new uint();

            r = skycoin.skycoin.SKY_coin_Transaction_PushInput(handle, h);
            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
            err = skycoin.skycoin.SKY_coin_Transaction_PushOutput(handle, makeAddress(), (ulong)1e6, 50);
            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
            err = skycoin.skycoin.SKY_coin_Transaction_PushOutput(handle, makeAddress(), (ulong)5e6, 50);
            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
            var seckeys = new cipher_SecKeys();

            seckeys.allocate(1);
            seckeys.setAt(0, s);
            err = skycoin.skycoin.SKY_coin_Transaction_SignInputs(handle, seckeys);
            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
            err = skycoin.skycoin.SKY_coin_Transaction_UpdateHeader(handle);
            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
            err = skycoin.skycoin.SKY_coin_GetTransactionObject(handle, ptx);
            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
            err = skycoin.skycoin.SKY_coin_Transaction_Verify(handle);
            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
        }
        public void TestSHA256KnownValue()
        {
            StrTest caseval;

            caseval.input  = "skycoin";
            caseval.output = "5a42c0643bdb465d90bf673b99c14f5fa02db71513249d904573d2b8b63d353d";
            StrTest caseval1;

            caseval1.input  = "hello world";
            caseval1.output = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9";
            StrTest caseval2;

            caseval2.input  = "hello world asd awd awd awdapodawpokawpod ";
            caseval2.output = "99d71f95cafe05ea2dddebc35b6083bd5af0e44850c9dc5139b4476c99950be4";
            StrTest[] val = { caseval, caseval1, caseval2 };

            for (int i = 0; i < val.Length; i++)
            {
                var io     = val[i];
                var b      = new GoSlice();
                var h      = new cipher_SHA256();
                var input  = new _GoString_();
                var output = new _GoString_();
                input.p = io.input;
                b.convertString(input);
                var err = SKY_cipher_SumSHA256(b, h);
                Assert.AreEqual(err, SKY_OK);
                err = SKY_cipher_SHA256_Hex(h, output);
                Assert.AreEqual(err, SKY_OK);
                Assert.AreEqual(output.p == io.output, true);
            }
        }
        public void TestSHA256Set()
        {
            var h   = new cipher_SHA256();
            var b   = new GoSlice();
            var err = SKY_cipher_RandByte(33, b);

            err = SKY_cipher_SHA256_Set(h, b);
            Assert.AreEqual(err, SKY_ErrInvalidLengthSHA256);
            h = new cipher_SHA256();
            b = new GoSlice();
            SKY_cipher_RandByte(100, b);
            err = SKY_cipher_SHA256_Set(h, b);
            Assert.AreEqual(err, SKY_ErrInvalidLengthSHA256);
            h = new cipher_SHA256();
            b = new GoSlice();
            SKY_cipher_RandByte(31, b);
            err = SKY_cipher_SHA256_Set(h, b);
            Assert.AreEqual(err, SKY_ErrInvalidLengthSHA256);
            h = new cipher_SHA256();
            b = new GoSlice();
            SKY_cipher_RandByte(0, b);
            err = SKY_cipher_SHA256_Set(h, b);
            Assert.AreEqual(err, SKY_ErrInvalidLengthSHA256);
            h = new cipher_SHA256();
            b = new GoSlice();
            SKY_cipher_RandByte(32, b);
            err = SKY_cipher_SHA256_Set(h, b);
            Assert.AreEqual(err, SKY_OK);
        }
        public void TestBlockHashBody()
        {
            var uxHash = transutils.RandSHA256();
            var b      = new_Block__HandlePtr();
            var err    = makeNewBlock(uxHash, b);

            Assert.AreEqual(err, SKY_OK);

            var sha1 = new cipher_SHA256();
            var sha2 = new cipher_SHA256();

            SKY_coin_Block_HashBody(b, sha1);
            var body = new_BlockBody__HandlePtr();

            SKY_coin_GetBlockBody(b, body);
            SKY_coin_BlockBody_Hash(body, sha2);
            Assert.AreEqual(sha1.isEqual(sha2), 1);
            var hb = new cipher_SHA256();

            SKY_coin_Block_HashBody(b, hb);
            var bh = new cipher_SHA256();

            SKY_coin_BlockBody_Hash(body, bh);
            Assert.AreEqual(bh.isEqual(hb), 1);
        }
        public void TestCreateUnspents()
        {
            var a = new cipher__Address();
            var p = new cipher_PubKey();
            var s = new cipher_SecKey();

            var err = SKY_cipher_GenerateKeyPair(p, s);

            Assert.AreEqual(err, SKY_OK);
            err = SKY_cipher_AddressFromPubKey(p, a);
            Assert.AreEqual(err, SKY_OK);
            var h   = new cipher_SHA256();
            var txn = new_Transaction__Handlep();

            makeEmptyTransaction(txn);
            err = SKY_coin_Transaction_PushOutput(txn, a, (ulong)11e6, 255);
            Assert.AreEqual(err, SKY_OK);
            var bh = new coin__BlockHeader();

            bh.Time  = 0;
            bh.BkSeq = 1;
            var uxouts = new coin_UxOutArray();

            err = SKY_coin_CreateUnspents(bh, txn, uxouts);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(uxouts.count, 1);
        }
        public uint makeNewBlock(cipher_SHA256 uxHash, SWIGTYPE_p_Block__Handle newBlock)
        {
            var bodyhash     = new cipher_SHA256();
            var block        = new_Block__HandlePtr();
            var transactions = makeTestTransactions();
            var err          = SKY_coin_NewEmptyBlock(transactions, block);

            Assert.AreEqual(err, SKY_OK);

            var pBlockHeader = new_BlockHeader__HandlePtr();

            err = SKY_coin_Block_GetBlockHeader(block, pBlockHeader);
            Assert.AreEqual(err, SKY_OK);

            SKY_coin_BlockHeader_SetTime(pBlockHeader, 100);
            SKY_coin_BlockHeader_SetBkSeq(pBlockHeader, 0);
            SKY_coin_BlockHeader_SetVersion(pBlockHeader, 0x02);
            SKY_coin_BlockHeader_SetFee(pBlockHeader, 10);

            var body = new_BlockBody__HandlePtr();

            err = SKY_coin_GetBlockBody(block, body);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_BlockBody_Hash(body, bodyhash);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_NewBlock(block, 100 + 200, uxHash, transactions, transutils.feeCalc, newBlock);
            Assert.AreEqual(err, SKY_OK);
            return(err);
        }
Exemple #7
0
        public void TestUxBodyHash()
        {
            var uxb  = transutils.makeUxBody();
            var hasx = new cipher_SHA256();
            var err  = SKY_coin_UxBody_Hash(uxb, hasx);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hasx.isEqual(new cipher_SHA256()), 0);
        }
        public cipher_SHA256 RandSHA256()
        {
            var sha = new cipher_SHA256();
            var b   = new GoSlice();
            var err = skycoin.skycoin.SKY_cipher_RandByte(128, b);

            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
            err = skycoin.skycoin.SKY_cipher_SumSHA256(b, sha);
            Assert.AreEqual(err, skycoin.skycoin.SKY_OK);
            return(sha);
        }
Exemple #9
0
        public void TestTransactionHash()
        {
            var handle = new_Transaction__Handlep();

            makeTransaction(handle);
            var h   = new cipher_SHA256();
            var h2  = new cipher_SHA256();
            var err = SKY_coin_Transaction_Hash(handle, h);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(h.isEqual(h2), 0);
            err = SKY_coin_Transaction_HashInner(handle, h2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(h.isEqual(h2), 0);
        }
        public void TestCreateUnspent()
        {
            var p = new cipher_PubKey();
            var s = new cipher_SecKey();
            var a = new cipher__Address();

            var err = SKY_cipher_GenerateKeyPair(p, s);

            Assert.AreEqual(err, SKY_OK);
            err = SKY_cipher_AddressFromPubKey(p, a);
            Assert.AreEqual(err, SKY_OK);
            var h      = new cipher_SHA256();
            var handle = new_Transaction__Handlep();

            makeEmptyTransaction(handle);
            err = SKY_coin_Transaction_PushOutput(handle, a, 11000000, 255);
            Assert.AreEqual(err, SKY_OK);
            var bh = new coin__BlockHeader();

            bh.Time  = 0;
            bh.BkSeq = 1;
            testcase[] t  = new testcase[2];
            var        tc = new testcase();

            tc.index   = 0;
            tc.failure = SKY_OK;
            t[0]       = tc;
            tc         = new testcase();
            tc.failure = SKY_ERROR;
            tc.index   = 10;
            t[1]       = tc;
            var ux          = new coin__UxOut();
            var tests_count = t.Length;

            for (int i = 0; i < tests_count; i++)
            {
                err = SKY_coin_CreateUnspent(bh, handle, t[i].index, ux);
                if (t[i].failure == SKY_ERROR)
                {
                    continue;
                }
                Assert.AreEqual(bh.Time, ux.Head.Time);
                Assert.AreEqual(bh.BkSeq, ux.Head.BkSeq);
            }
        }
Exemple #11
0
        public bool manualUxArrayIsSorted(coin_UxOutArray uxa)
        {
            var sha_1  = new cipher_SHA256();
            var sha_2  = new cipher_SHA256();
            var isSort = true;

            for (int i = 0; i < uxa.count - 1; i++)
            {
                var err = SKY_coin_UxOut_Hash(uxa.getAt(i), sha_1);
                Assert.AreEqual(err, SKY_OK);
                err = SKY_coin_UxOut_Hash(uxa.getAt(i + 1), sha_2);
                Assert.AreEqual(err, SKY_OK);
                if (sha_1.isEqual(sha_2) == 0)
                {
                    isSort = false;
                }
            }
            return(isSort);
        }
        public void makeUxBodyWithSecret(coin__UxBody uxBody, cipher_SecKey secKey)
        {
            var p = new cipher_PubKey();

            skycoin.skycoin.SKY_cipher_GenerateKeyPair(p, secKey);
            var b = new GoSlice();

            skycoin.skycoin.SKY_cipher_RandByte(128, b);
            var h = new cipher_SHA256();

            skycoin.skycoin.SKY_cipher_SumSHA256(b, h);
            uxBody.SetSrcTransaction(h);
            var a = new cipher__Address();

            skycoin.skycoin.SKY_cipher_AddressFromPubKey(p, a);
            uxBody.Address = a;
            uxBody.Coins   = (ulong)(1e6);
            uxBody.Hours   = 100;
        }
        public void TestBlockHashHeader()
        {
            var uxHash = transutils.RandSHA256();
            var b      = new_Block__HandlePtr();
            var err    = makeNewBlock(uxHash, b);

            Assert.AreEqual(err, SKY_OK);

            var sha1 = new cipher_SHA256();
            var sha2 = new cipher_SHA256();

            err = SKY_coin_Block_HashHeader(b, sha1);
            Assert.AreEqual(err, SKY_OK);
            var blockheader = new_BlockHeader__HandlePtr();

            err = SKY_coin_Block_GetBlockHeader(b, blockheader);
            err = SKY_coin_BlockHeader_Hash(blockheader, sha2);
            Assert.AreEqual(sha1.isEqual(sha2), 1);
            Assert.AreEqual(sha1.isEqual(new cipher_SHA256()), 0);
        }
        public void TestSumSHA256()
        {
            var b   = new GoSlice();
            var err = SKY_cipher_RandByte(256, b);
            var h1  = new cipher_SHA256();

            err = SKY_cipher_SumSHA256(b, h1);
            Assert.AreEqual(h1.isEqual(new cipher_SHA256()), 0);
            // A second call to Sum should not be influenced by the original
            var c = new GoSlice();

            err = SKY_cipher_RandByte(256, c);
            var h2 = new cipher_SHA256();

            err = SKY_cipher_SumSHA256(c, h2);
            Assert.AreEqual(h2.isEqual(new cipher_SHA256()), 0);
            var h3 = new cipher_SHA256();

            freshSumSHA256(c, h3);
            Assert.AreEqual(h2.isEqual(h3), 1);
        }
        public void TestSignHash()
        {
            var p = new cipher_PubKey();
            var s = new cipher_SecKey();
            var a = new cipher__Address();

            SKY_cipher_GenerateKeyPair(p, s);
            var err = SKY_cipher_AddressFromPubKey(p, a);

            Assert.AreEqual(err, SKY_OK);
            var b_temp = new GoSlice();

            SKY_cipher_RandByte(256, b_temp);
            var h = new cipher_SHA256();

            SKY_cipher_SumSHA256(b_temp, h);
            var sig = new cipher_Sig();

            SKY_cipher_SignHash(h, s, sig);
            Assert.AreEqual(sig.isEqual(new cipher_Sig()), 0);
        }
        public void TestPubKeyFromSig()
        {
            var p   = new cipher_PubKey();
            var s   = new cipher_SecKey();
            var b   = new GoSlice();
            var h   = new cipher_SHA256();
            var err = SKY_cipher_GenerateKeyPair(p, s);

            err = SKY_cipher_RandByte(256, b);
            err = SKY_cipher_SumSHA256(b, h);
            var sig = new cipher_Sig();

            err = SKY_cipher_SignHash(h, s, sig);
            var p2 = new cipher_PubKey();

            err = SKY_cipher_PubKeyFromSig(sig, h, p2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(p2.isEqual(p), 1);
            p2  = new cipher_PubKey();
            err = SKY_cipher_PubKeyFromSig(new cipher_Sig(), h, p2);
            Assert.AreEqual(err, SKY_ErrInvalidSigPubKeyRecovery);
        }
        public void TestNewGenesisBlock()
        {
            var   pubkey   = new cipher_PubKey();
            var   seckey   = new cipher_SecKey();
            ulong genTime  = 1000;
            ulong genCoins = (ulong)1000e6;

            var err = SKY_cipher_GenerateKeyPair(pubkey, seckey);

            Assert.AreEqual(err, SKY_OK);
            var addr = new cipher__Address();

            err = SKY_cipher_AddressFromPubKey(pubkey, addr);
            Assert.AreEqual(err, SKY_OK);
            var block = new_Block__HandlePtr();

            err = SKY_coin_NewGenesisBlock(addr, genCoins, genTime, block);
            Assert.AreEqual(err, SKY_OK);
            var pBlockPP = new_coin__BlockPtr();

            err = SKY_coin_GetBlockObject(block, pBlockPP);
            var pBlock = coin__BlockPtr_value(pBlockPP);

            Assert.AreEqual(err, SKY_OK);
            var nullHash = new cipher_SHA256();
            var Head     = new GoSlice();

            err = SKY_coin_BlockHeader_Bytes(pBlock.Head, Head);
            Assert.AreEqual(err, SKY_OK);
            var strnullHash = nullHash.getStr();
            var strHead     = new _GoString_();

            Head.getString(strHead);
            Assert.AreEqual(strnullHash.p, strHead.p);
            Assert.AreEqual(genTime, pBlock.Head.Time);
            Assert.AreEqual(0, pBlock.Head.BkSeq);
            Assert.AreEqual(0, pBlock.Head.Version);
            Assert.AreEqual(0, pBlock.Head.Fee);
        }
Exemple #18
0
        public void TestTransactionPushInput()
        {
            var tx = new_Transaction__Handlep();

            makeEmptyTransaction(tx);
            var ux = new coin__UxOut();

            makeUxOut(ux);
            var sha = new cipher_SHA256();
            var err = SKY_coin_UxOut_Hash(ux, sha);

            Assert.AreEqual(err, SKY_OK);
            var r = new uint();

            r = SKY_coin_Transaction_PushInput(tx, sha);
            Assert.AreEqual(r, 0);
            var count = new_Gointp();

            err = SKY_coin_Transaction_GetInputsCount(tx, count);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(Gointp_value(count), 1);
            var sha1 = new cipher_SHA256();

            err = SKY_coin_Transaction_GetInputAt(tx, 0, sha1);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(sha.isEqual(sha1), 1);
            err = SKY_coin_Transaction_ResetInputs(tx, 0);
            Assert.AreEqual(err, SKY_OK);
            for (int i = 0; i < short.MaxValue; i++)
            {
                r = new uint();
                r = SKY_coin_Transaction_PushInput(tx, new cipher_SHA256());
                Assert.AreEqual(r, SKY_OK);
            }
            makeUxOut(ux);
            err = SKY_coin_UxOut_Hash(ux, sha);
            Assert.AreEqual(err, SKY_OK);
        }
        public void TestSHA256Hex()
        {
            var h = new cipher_SHA256();
            var b = new GoSlice();

            SKY_cipher_RandByte(32, b);
            var err = SKY_cipher_SHA256_Set(h, b);

            Assert.AreEqual(err, SKY_OK);
            var s = new _GoString_();

            err = SKY_cipher_SHA256_Hex(h, s);
            var h2 = new cipher_SHA256();

            err = SKY_cipher_SHA256FromHex(s.p, h2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(h.isEqual(h2), 1);
            var s1 = new _GoString_();

            err = SKY_cipher_SHA256_Hex(h, s1);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(s1.p == s.p, true);
        }
Exemple #20
0
        public void TestTransactionsHashes()
        {
            var handle = new_Transactions__HandlePtr();

            makeTransactions(4, handle);
            var hashes = new cipher_SHA256s();
            var err    = SKY_coin_Transactions_Hashes(handle, hashes);

            Assert.AreEqual(err, SKY_OK);
            var len_hashes = hashes.count;

            Assert.AreEqual(len_hashes, 4);
            for (int i = 0; i < len_hashes; i++)
            {
                var tx = new_Transaction__Handlep();
                err = SKY_coin_Transactions_GetAt(handle, i, tx);
                Assert.AreEqual(err, SKY_OK);
                var h = new cipher_SHA256();
                err = SKY_coin_Transaction_Hash(tx, h);
                Assert.AreEqual(err, SKY_OK);
                Assert.AreEqual(h.isEqual(hashes.getAt(i)), 1);
            }
        }
Exemple #21
0
        public void TestTransactionUpdateHeader()
        {
            var handle = new_Transaction__Handlep();
            var tx     = makeTransaction(handle);
            var h      = new cipher_SHA256();
            var h1     = new cipher_SHA256();
            var h2     = new cipher_SHA256();
            var err    = SKY_coin_Transaction_HashInner(handle, h);

            Assert.AreEqual(err, SKY_OK);
            tx.setInnerHash(new cipher_SHA256());
            err = SKY_coin_Transaction_UpdateHeader(handle);
            Assert.AreEqual(err, SKY_OK);
            var arg = new cipher_SHA256();

            arg = tx.GetInnerHash();
            h1.assignFrom(arg);
            err = SKY_coin_Transaction_HashInner(handle, h2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(h1.isEqual(new cipher_SHA256()), 0);
            Assert.AreEqual(h1.isEqual(h), 1);
            Assert.AreEqual(h1.isEqual(h2), 1);
        }
Exemple #22
0
        public void TestUxArrayHashArray()
        {
            var uxa = new coin_UxOutArray();

            makeUxArray(uxa, 4);
            var sha    = new cipher_SHA256();
            var hashes = new cipher_SHA256s();
            var err    = SKY_coin_UxArray_Hashes(uxa, hashes);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hashes.count, uxa.count);
            var uxo = uxa.getAt(0);

            err = SKY_coin_UxOut_Hash(uxo, sha);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hashes.getAt(0).isEqual(sha), 1);
            for (int i = 0; i < hashes.count; i++)
            {
                err = SKY_coin_UxOut_Hash(uxa.getAt(i), sha);
                Assert.AreEqual(err, SKY_OK);
                Assert.AreEqual(sha.isEqual(hashes.getAt(i)), 1);
            }
        }
Exemple #23
0
        public void TestUxOutHash()
        {
            var uxb = transutils.makeUxBody();
            var uxo = transutils.makeUxOut();

            uxo.Body = uxb;
            var hash_body = new cipher_SHA256();
            var hash_out  = new cipher_SHA256();
            var err       = SKY_coin_UxBody_Hash(uxb, hash_body);

            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_UxOut_Hash(uxo, hash_out);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hash_body.isEqual(hash_out), 1);
            //  Head should not affect hash
            var uxh = new coin__UxHead();

            uxh.Time  = 0;
            uxh.BkSeq = 1;
            uxo.Head  = uxh;
            err       = SKY_coin_UxOut_Hash(uxo, hash_out);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hash_body.isEqual(hash_out), 1);
        }
 void freshSumSHA256(GoSlice bytes, cipher_SHA256 sha256)
 {
     SKY_cipher_SumSHA256(bytes, sha256);
 }
Exemple #25
0
        public void TestTransactionVerify()
        {
            // Mismatch header hash
            var tx  = transutils.makeEmptyTransaction();
            var ptx = makeTransaction(tx);

            ptx.setInnerHash(new cipher_SHA256());
            var err = SKY_coin_Transaction_Verify(tx);

            Assert.AreEqual(err, SKY_ERROR);

            // No inputs
            tx = new_Transaction__Handlep();
            makeTransaction(tx);
            err = SKY_coin_Transaction_ResetInputs(tx, 0);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_ERROR);

            // No outputs
            makeTransaction(tx);
            err = SKY_coin_Transaction_ResetOutputs(tx, 0);
            Assert.AreEqual(err, SKY_OK, "");
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_ERROR);

            // Invalid number of Sigs
            makeTransaction(tx);
            err = SKY_coin_Transaction_ResetSignatures(tx, 0);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_ERROR);
            err = SKY_coin_Transaction_ResetSignatures(tx, 20);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_ERROR);

            // Too many sigs & inputs
            makeTransaction(tx);
            err = SKY_coin_Transaction_ResetSignatures(tx, short.MaxValue);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_ResetInputs(tx, short.MaxValue);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_ERROR);

            // Duplicate inputs
            var ux = new coin__UxOut();
            var s  = new cipher_SecKey();
            var h  = new cipher_SHA256();

            makeUxOutWithSecret(ux, s);
            makeTransactionFromUxOut(ux, s, tx);
            err = SKY_coin_Transaction_GetInputAt(tx, 0, h);
            Assert.AreEqual(err, SKY_OK);
            var r = new uint();

            r = SKY_coin_Transaction_PushInput(tx, h);
            Assert.AreEqual(r, SKY_OK);
            err = SKY_coin_Transaction_ResetSignatures(tx, 0);
            Assert.AreEqual(err, SKY_OK);
            var secKeys = new cipher_SecKeys();

            secKeys.allocate(2);
            secKeys.setAt(0, s);
            secKeys.setAt(1, s);
            err = SKY_coin_Transaction_SignInputs(tx, secKeys);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_ERROR);

            // Duplicate outputs
            makeTransaction(tx);
            var pOutput = new coin__TransactionOutput();

            err             = SKY_coin_Transaction_GetOutputAt(tx, 0, pOutput);
            pOutput.Address = new cipher__Address();
            err             = SKY_coin_Transaction_ResetOutputs(tx, 0);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_PushOutput(tx, pOutput.Address, pOutput.Coins, pOutput.Hours);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_PushOutput(tx, pOutput.Address, pOutput.Coins, pOutput.Hours);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_ERROR);

            // Output coins are 0
            makeTransaction(tx);
            err           = SKY_coin_Transaction_GetOutputAt(tx, 0, pOutput);
            pOutput.Coins = 0;
            err           = SKY_coin_Transaction_ResetOutputs(tx, 0);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_PushOutput(tx, pOutput.Address, pOutput.Coins, pOutput.Hours);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_ERROR);

            // Output coin overflow
            makeTransaction(tx);
            err           = SKY_coin_Transaction_GetOutputAt(tx, 0, pOutput);
            pOutput.Coins = (ulong)(ulong.MaxValue - 3e6);
            err           = SKY_coin_Transaction_PushOutput(tx, pOutput.Address, pOutput.Coins, pOutput.Hours);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_ERROR);

            // Output coins are not multiples of 1e6 (valid, decimal restriction is not enforced here)
            makeTransaction(tx);
            err = SKY_coin_Transaction_GetOutputAt(tx, 0, pOutput);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_ResetOutputs(tx, 0);
            Assert.AreEqual(err, SKY_OK);
            pOutput.Coins += 10;
            err            = SKY_coin_Transaction_PushOutput(tx, pOutput.Address, pOutput.Coins, pOutput.Hours);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_ResetSignatures(tx, 0);
            Assert.AreEqual(err, SKY_OK);
            var p = new cipher_PubKey();

            s   = new cipher_SecKey();
            err = SKY_cipher_GenerateKeyPair(p, s);
            Assert.AreEqual(err, SKY_OK);
            secKeys = new cipher_SecKeys();
            secKeys.allocate(1);
            secKeys.setAt(0, s);
            err = SKY_coin_Transaction_SignInputs(tx, secKeys);
            Assert.AreEqual(err, SKY_OK);
            Assert.IsTrue(pOutput.Coins % 1e6 != 0);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_OK);
            // Valid
            makeTransaction(tx);
            err = SKY_coin_Transaction_GetOutputAt(tx, 0, pOutput);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_ResetOutputs(tx, 0);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_PushOutput(tx, pOutput.Address, (ulong)(10e6), pOutput.Hours);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_PushOutput(tx, pOutput.Address, (ulong)(1e6), pOutput.Hours);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_UpdateHeader(tx);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_Verify(tx);
            Assert.AreEqual(err, SKY_OK);
        }
Exemple #26
0
        public void TestTransactionSignInputs()
        {
            var handle = transutils.makeEmptyTransaction();
            //  Panics if txns already signed
            var sig = new cipher_Sig();
            var err = SKY_coin_Transaction_PushSignature(handle, sig);

            Assert.AreEqual(err, SKY_OK);
            var seckeys = new cipher_SecKeys();

            seckeys.allocate(1);
            seckeys.setAt(0, new cipher_SecKey());
            // Panics if not enough keys
            handle = transutils.makeEmptyTransaction();
            var s   = new cipher_SecKey();
            var s2  = new cipher_SecKey();
            var ux  = new coin__UxOut();
            var ux2 = new coin__UxOut();

            makeUxOutWithSecret(ux, s);
            var h = new cipher_SHA256();

            err = SKY_coin_UxOut_Hash(ux, h);
            Assert.AreEqual(err, SKY_OK);
            var r = new uint();

            r = SKY_coin_Transaction_PushInput(handle, h);
            Assert.AreEqual(r, SKY_OK);
            makeUxOutWithSecret(ux2, s2);
            err = SKY_coin_UxOut_Hash(ux2, h);
            Assert.AreEqual(err, SKY_OK);
            r = SKY_coin_Transaction_PushInput(handle, h);
            Assert.AreEqual(r, SKY_OK);
            err = SKY_coin_Transaction_PushOutput(handle, transutils.makeAddress(), 40, 80);
            Assert.AreEqual(err, SKY_OK);
            var count = new_Gointp();

            err = SKY_coin_Transaction_GetSignaturesCount(handle, count);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(Gointp_value(count), 0);
            // Valid signing
            h = new cipher_SHA256();
            SKY_coin_Transaction_HashInner(handle, h);
            seckeys = new cipher_SecKeys();
            seckeys.allocate(2);
            seckeys.setAt(0, s);
            seckeys.setAt(1, s2);
            err = SKY_coin_Transaction_SignInputs(handle, seckeys);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_GetSignaturesCount(handle, count);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(Gointp_value(count), 2);
            var h2 = new cipher_SHA256();

            err = SKY_coin_Transaction_HashInner(handle, h2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(h.isEqual(h2), 1);
            var p = new cipher_PubKey();

            err = SKY_cipher_PubKeyFromSecKey(s, p);
            Assert.AreEqual(err, SKY_OK);
            var a  = new cipher__Address();
            var a2 = new cipher__Address();

            err = SKY_cipher_AddressFromPubKey(p, a);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_cipher_PubKeyFromSecKey(s2, p);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_cipher_AddressFromPubKey(p, a2);
            Assert.AreEqual(err, SKY_OK);
            var sha1  = new cipher_SHA256();
            var sha2  = new cipher_SHA256();
            var txin0 = new cipher_SHA256();
            var txin1 = new cipher_SHA256();

            err = SKY_coin_Transaction_GetInputAt(handle, 0, txin0);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_GetInputAt(handle, 1, txin1);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_cipher_AddSHA256(h, txin0, sha1);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_cipher_AddSHA256(h, txin1, sha2);
            Assert.AreEqual(err, SKY_OK);
            var txsig0 = new cipher_Sig();
            var txsig1 = new cipher_Sig();

            err = SKY_coin_Transaction_GetSignatureAt(handle, 0, txsig0);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_GetSignatureAt(handle, 1, txsig1);
            Assert.AreEqual(err, SKY_OK);
        }
Exemple #27
0
        public void TestTransactionHashInner()
        {
            var handle = new_Transaction__Handlep();

            makeTransaction(handle);
            var h   = new cipher_SHA256();
            var err = SKY_coin_Transaction_HashInner(handle, h);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(h.isEqual(new cipher_SHA256()), 0);

            // If tx.In is changed, hash should change
            var handle2 = transutils.copyTransaction(handle);

            Assert.AreEqual(err, SKY_OK);
            var ux = new coin__UxOut();

            makeUxOut(ux);
            h = new cipher_SHA256();
            var h1 = new cipher_SHA256();

            err = SKY_coin_UxOut_Hash(ux, h);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_SetInputAt(handle2, 0, h);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_UxOut_Hash(ux, h1);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(h.isEqual(h1), 1);
            err = SKY_coin_Transaction_HashInner(handle, h);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_HashInner(handle2, h1);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(h.isEqual(h1), 0);

            // If tx.Out is changed, hash should change
            handle2 = transutils.copyTransaction(handle);
            var a    = transutils.makeAddress();
            var pOut = new coin__TransactionOutput();

            err = SKY_coin_Transaction_GetOutputAt(handle2, 0, pOut);
            Assert.AreEqual(err, SKY_OK);
            pOut.Address = a;
            err          = SKY_coin_Transaction_SetOutputAt(handle2, 0, pOut);
            Assert.AreEqual(err, SKY_OK);
            var sha1 = new cipher_SHA256();
            var sha2 = new cipher_SHA256();

            err = SKY_coin_Transaction_HashInner(handle, sha1);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_HashInner(handle2, sha2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(sha1.isEqual(sha2), 0);

            // If tx.Head is changed, hash should not change
            handle2 = transutils.copyTransaction(handle);
            var sig = new cipher_Sig();

            err = SKY_coin_Transaction_PushSignature(handle, sig);
            Assert.AreEqual(err, SKY_OK);
            sha1 = new cipher_SHA256();
            sha2 = new cipher_SHA256();
            err  = SKY_coin_Transaction_HashInner(handle, sha1);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_HashInner(handle2, sha2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(sha1.isEqual(sha2), 1);
        }
Exemple #28
0
        public void TestUxOutSnapshotHash()
        {
            var p   = new cipher_PubKey();
            var s   = new cipher_SecKey();
            var err = SKY_cipher_GenerateKeyPair(p, s);

            Assert.AreEqual(err, SKY_OK);
            var uxb = new coin__UxBody();
            var b   = new GoSlice();

            err = SKY_cipher_RandByte(128, b);
            Assert.AreEqual(err, SKY_OK);
            var h = new cipher_SHA256();

            err = SKY_cipher_SumSHA256(b, h);
            Assert.AreEqual(err, SKY_OK);
            uxb.SetSrcTransaction(h);
            var a = new cipher__Address();

            err = SKY_cipher_AddressFromPubKey(p, a);
            Assert.AreEqual(err, SKY_OK);
            uxb.Address = a;
            uxb.Coins   = (ulong)1e6;
            uxb.Hours   = (ulong)100;
            var uxo = new coin__UxOut();
            var uxh = new coin__UxHead();

            uxh.Time  = 100;
            uxh.BkSeq = 2;
            uxo.Head  = uxh;
            uxo.Body  = uxb;
            var hn = new cipher_SHA256();

            err = SKY_coin_UxOut_SnapshotHash(uxo, hn);
            Assert.AreEqual(err, SKY_OK);
            // snapshot hash should be dependent on every field in body and head
            // Head Time
            var uxo_2 = uxo;

            uxh.Time   = 20;
            uxo_2.Head = uxh;
            var hn_2 = new cipher_SHA256();

            err = SKY_coin_UxOut_SnapshotHash(uxo_2, hn_2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hn.isEqual(hn_2), 0);
            // Head BkSeq
            uxo_2      = uxo;
            uxh.BkSeq  = 4;
            uxo_2.Head = uxh;
            hn_2       = new cipher_SHA256();
            err        = SKY_coin_UxOut_SnapshotHash(uxo_2, hn_2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hn.isEqual(hn_2), 0);
            // Body SetSrcTransaction
            uxo_2 = uxo;
            uxb   = new coin__UxBody();
            err   = SKY_cipher_RandByte(128, b);
            Assert.AreEqual(err, SKY_OK);
            h   = new cipher_SHA256();
            err = SKY_cipher_SumSHA256(b, h);
            Assert.AreEqual(err, SKY_OK);
            uxb.SetSrcTransaction(h);
            uxo_2.Body = uxb;
            hn_2       = new cipher_SHA256();
            err        = SKY_coin_UxOut_SnapshotHash(uxo_2, hn_2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hn.isEqual(hn_2), 0);
            // Body Address
            var p_2 = new cipher_PubKey();
            var s_2 = new cipher_SecKey();

            err = SKY_cipher_GenerateKeyPair(p_2, s_2);
            Assert.AreEqual(err, SKY_OK);
            var a_2 = new cipher__Address();

            err = SKY_cipher_AddressFromPubKey(p_2, a_2);
            Assert.AreEqual(err, SKY_OK);
            uxo_2       = uxo;
            uxb         = new coin__UxBody();
            uxb.Address = a_2;
            uxo_2.Body  = uxb;
            hn_2        = new cipher_SHA256();
            err         = SKY_coin_UxOut_SnapshotHash(uxo_2, hn_2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hn.isEqual(hn_2), 0);
            // Body Coins
            uxo_2      = uxo;
            uxb        = new coin__UxBody();
            uxb.Coins  = 2;
            uxo_2.Body = uxb;
            hn_2       = new cipher_SHA256();
            err        = SKY_coin_UxOut_SnapshotHash(uxo_2, hn_2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hn.isEqual(hn_2), 0);
            // Body Hours
            uxo_2      = uxo;
            uxb        = new coin__UxBody();
            uxb.Hours  = 2;
            uxo_2.Body = uxb;
            hn_2       = new cipher_SHA256();
            err        = SKY_coin_UxOut_SnapshotHash(uxo_2, hn_2);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hn.isEqual(hn_2), 0);
        }
        public void TestNewBlock()
        {
            var prevBlock        = new_Block__HandlePtr();
            var newBlock         = new_Block__HandlePtr();
            var pPrevBlockHeader = new_BlockHeader__HandlePtr();
            var txns             = makeTestTransactions();
            var err = SKY_coin_NewEmptyBlock(txns, prevBlock);

            err = SKY_coin_Block_GetBlockHeader(prevBlock, pPrevBlockHeader);
            Assert.AreEqual(err, SKY_OK);

            SKY_coin_BlockHeader_SetTime(pPrevBlockHeader, 100);
            SKY_coin_BlockHeader_SetBkSeq(pPrevBlockHeader, 98);
            var uxHash = transutils.RandSHA256();

            // invalid txn fees panics
            txns = new_Transactions__HandlePtr();
            SKY_coin_Create_Transactions(txns);
            err = SKY_coin_NewBlock(prevBlock, 133, uxHash, txns, transutils.badCalc, newBlock);
            Assert.AreEqual(err, SKY_ERROR);
            // no txns panics
            txns = new_Transactions__HandlePtr();
            SKY_coin_Create_Transactions(txns);
            err = SKY_coin_NewBlock(prevBlock, 133, uxHash, txns, transutils.feeCalc, newBlock);
            Assert.AreEqual(err, SKY_ERROR);

            // Valid block in fine
            txns = new_Transactions__HandlePtr();
            err  = SKY_coin_Create_Transactions(txns);
            Assert.AreEqual(err, SKY_OK);
            var tnx = transutils.makeEmptyTransaction();

            err = SKY_coin_Transactions_Add(txns, tnx);
            Assert.AreEqual(err, SKY_OK);

            ulong fee         = 121;
            ulong currentTime = 133;

            newBlock = new_Block__HandlePtr();
            err      = SKY_coin_NewBlock(prevBlock, currentTime, uxHash, txns, transutils.fix121, newBlock);
            Assert.AreEqual(err, SKY_OK);

            var pnewBlockHeader = new_BlockHeader__HandlePtr();

            err = SKY_coin_Block_GetBlockHeader(newBlock, pnewBlockHeader);
            var pHeadFee   = new_GoUint64p();
            var pHeadTime  = new_GoUint64p();
            var pHeadBkSeq = new_GoUint64p();

            SKY_coin_BlockHeader_Fee(pnewBlockHeader, pHeadFee);
            SKY_coin_BlockHeader_Time(pnewBlockHeader, pHeadTime);
            SKY_coin_BlockHeader_BkSeq(pnewBlockHeader, pHeadBkSeq);
            var pTransLength = new_Gointp();

            err = SKY_coin_Transactions_Length(txns, pTransLength);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(pHeadFee), (fee * (ulong)Gointp_value(pTransLength)));
            Assert.AreEqual(GoUint64p_value(pHeadTime), currentTime);
            pPrevBlockHeader = new_BlockHeader__HandlePtr();
            err = SKY_coin_Block_GetBlockHeader(prevBlock, pPrevBlockHeader);
            Assert.AreEqual(err, SKY_OK);
            var pPrevBkSeq = new_GoUint64p();

            SKY_coin_BlockHeader_BkSeq(pPrevBlockHeader, pPrevBkSeq);
            var pnewuxHash = new cipher_SHA256();

            SKY_coin_BlockHeader_UxHash(pnewBlockHeader, pnewuxHash);
            Assert.AreEqual(pnewuxHash.isEqual(uxHash), 1);
        }
Exemple #30
0
        public void TestUxOutCoinHours()
        {
            var p = new cipher_PubKey();
            var s = new cipher_SecKey();

            SKY_cipher_GenerateKeyPair(p, s);
            var uxb = new coin__UxBody();
            var b   = new GoSlice();

            SKY_cipher_RandByte(128, b);
            var h   = new cipher_SHA256();
            var err = SKY_cipher_SumSHA256(b, h);

            Assert.AreEqual(err, SKY_OK);
            uxb.SetSrcTransaction(h);
            var a = new cipher__Address();

            SKY_cipher_AddressFromPubKey(p, a);
            uxb.Address = a;
            uxb.Coins   = (ulong)1e6;
            uxb.Hours   = 100;
            var uxo = new coin__UxOut();
            var uxh = new coin__UxHead();

            uxh.Time  = 100;
            uxh.BkSeq = 2;
            uxo.Head  = uxh;
            uxo.Body  = uxb;

            // Less than an hour passed
            var now   = uxh.Time + 100;
            var hours = new_GoUint64p();

            err = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(uxh.Time, GoUint64p_value(hours), "Less than an hour passed");
            // 1 hours passed
            now = uxh.Time + 3600;
            err = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), uxh.Time + (uxb.Coins / 1000000), "1 hours passed");
            // 6 hours passed
            now = uxh.Time + 3600 * 6;
            err = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), uxh.Time + (uxb.Coins / 1000000) * 6, "1 hours passed");
            // Time is backwards (treated as no hours passed)
            now = uxh.Time / 2;
            err = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), uxh.Time);
            // 1 hour has passed, output has 1.5 coins, should gain 1 coinhour
            uxb.Coins = 1500000;
            now       = uxh.Time + 3600;
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), uxb.Hours + 1);
            // 2 hours have passed, output has 1.5 coins, should gain 3 coin hours
            uxb.Coins = 1500000;
            uxo.Body  = uxb;
            now       = uxh.Time + 3600 * 2;
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            // 1 second has passed, output has 3600 coins, should gain 1 coin hour
            uxb.Coins = 3600000000;
            uxo.Body  = uxb;
            now       = uxh.Time + 1;
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), uxb.Hours + 1);
            // 1000000 hours minus 1 second have passed, output has 1 droplet, should gain 0 coin hour
            uxb.Coins = 1;
            uxo.Body  = uxb;
            now       = (ulong)(uxh.Time + (ulong)Convert.ToInt64(1e6 * 3600) - 1);
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), uxb.Hours);
            // 1000000 hours have passed, output has 1 droplet, should gain 1 coin hour
            uxb.Coins = 1;
            uxo.Body  = uxb;
            now       = uxh.Time + Convert.ToUInt64(10e5 * 3600);
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), uxb.Hours + 1);
            // No hours passed, using initial coin hours
            uxb.Coins = (ulong)10e8;
            uxb.Hours = 1000 * 1000;
            uxo.Body  = uxb;
            now       = uxh.Time;
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), uxb.Hours);
            // One hour passed, using initial coin hours
            now = uxh.Time + 3600;
            err = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), uxb.Hours + (10e8 / 10e5));
            // No hours passed and no hours to begin with 0
            uxb.Hours = 0;
            uxo.Body  = uxb;
            now       = uxh.Time;
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), 0);
            // Centuries have passed, time-based calculation overflows uint64 when calculating the whole coin seconds
            uxb.Coins = (ulong)20e5;
            uxo.Body  = uxb;
            now       = 0xFFFFFFFFFFFFFFFF;
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_ERROR);
            // Centuries have passed, time-based calculation overflows uint64 when calculating the droplet seconds
            uxb.Coins = (ulong)15e5;
            uxo.Body  = uxb;
            now       = 0xFFFFFFFFFFFFFFFF;
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_ERROR);
            // Output would overflow if given more hours, has reached its limit
            uxb.Coins = (ulong)36e8;
            uxo.Body  = uxb;
            now       = 0xFFFFFFFFFFFFFFFF;
            err       = SKY_coin_UxOut_CoinHours(uxo, now, hours);
            Assert.AreEqual(err, SKY_ERROR);
        }