public void TxidAndOutPointTest() { string txidStr = "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f"; string txidStrReverse = "0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a157"; Txid txid = new Txid(txidStr); Assert.Equal(txidStr, txid.ToHexString()); Assert.Equal(txidStrReverse, StringUtil.FromBytes(txid.GetBytes())); Txid copyTxid = new Txid(txid.GetBytes()); Assert.Equal(txidStr, copyTxid.ToHexString()); Txid txid1 = new Txid("57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f"); Txid txid2 = new Txid("57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f"); Txid txid3 = new Txid("99a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f"); Txid txid4 = null; Txid txid5 = null; Assert.True((txid1 == txid2)); Assert.False((txid1 == txid3)); Assert.False((txid1 == txid4)); Assert.True((txid4 == txid5)); OutPoint p1 = new OutPoint(txid1, 0); OutPoint p2 = new OutPoint(txid2, 0); OutPoint p3 = new OutPoint(txid3, 0); OutPoint p4 = null; OutPoint p5 = null; Assert.True((p1 == p2)); Assert.False((p1 == p3)); Assert.False((p1 == p4)); Assert.True((p4 == p5)); }
public void GetTxInfoTest() { ExtPrivkey privkey = new ExtPrivkey("xprv9zt1onyw8BdEf7SQ6wUVH3bQQdGD9iy9QzXveQQRhX7i5iUN7jZgLbqFEe491LfjozztYa6bJAGZ65GmDCNcbjMdjZcgmdisPJwVjcfcDhV"); Address addr1 = new Address(privkey.DerivePubkey(1).GetPubkey(), CfdAddressType.P2wpkh, CfdNetworkType.Regtest); Address addr2 = new Address(privkey.DerivePubkey(2).GetPubkey(), CfdAddressType.P2wpkh, CfdNetworkType.Regtest); Address addr3 = new Address(privkey.DerivePubkey(3).GetPubkey(), CfdAddressType.P2wpkh, CfdNetworkType.Regtest); OutPoint outpoint1 = new OutPoint("0000000000000000000000000000000000000000000000000000000000000001", 2); OutPoint outpoint2 = new OutPoint("0000000000000000000000000000000000000000000000000000000000000001", 3); var txins = new[] { new TxIn(outpoint1), new TxIn(outpoint2), }; var txouts = new[] { new TxOut(10000, addr1.GetLockingScript()), new TxOut(10000, addr2.GetLockingScript()), }; Transaction tx = new Transaction("02000000000000000000", txins, txouts); tx.AddTxOut(50000, addr3); output.WriteLine("tx:\n" + tx.ToHexString()); Assert.Equal("020000000201000000000000000000000000000000000000000000000000000000000000000200000000ffffffff01000000000000000000000000000000000000000000000000000000000000000300000000ffffffff0310270000000000001600148b756cbd98f4f55e985f80437a619d47f0732a941027000000000000160014c0a3dd0b7c1b3281be91112e16ce931dbac2a97950c3000000000000160014ad3abd3c325e40e20d89aa054dd980b97494f16c00000000", tx.ToHexString()); Privkey privkey1 = privkey.DerivePrivkey(11).GetPrivkey(); SignatureHashType sighashType = new SignatureHashType(CfdSighashType.All, false); tx.AddSignWithPrivkeySimple(outpoint1, CfdHashType.P2wpkh, privkey1, 50000, sighashType); // output.WriteLine("tx:\n" + tx.ToHexString()); Assert.Equal("0200000000010201000000000000000000000000000000000000000000000000000000000000000200000000ffffffff01000000000000000000000000000000000000000000000000000000000000000300000000ffffffff0310270000000000001600148b756cbd98f4f55e985f80437a619d47f0732a941027000000000000160014c0a3dd0b7c1b3281be91112e16ce931dbac2a97950c3000000000000160014ad3abd3c325e40e20d89aa054dd980b97494f16c02473044022034db802aad655cd9be589075fc8ef325b6ffb8c24e5b27eb87bde8ad38f5fd7a0220364c916c8e8fc0adf714d7148cd1c6dc6f3e67d55471e57233b1870c65ec2727012103782f0ea892d7000e5f0f82b6ff283382a76500137a542bb0a616530094a8f54c0000000000", tx.ToHexString()); Txid txid = tx.GetTxid(); output.WriteLine("txid: " + txid.ToHexString()); Assert.Equal("67e1878d1621e77e166bed9d726bff27b2afcde9eb3dbb1ae3088d0387f40be4", txid.ToHexString()); Txid wtxid = tx.GetWtxid(); output.WriteLine("wtxid: " + wtxid.ToHexString()); Assert.Equal("24c66461b4b38c750fa4528d0cf3aea9a13d3156c0a73cfd6fca6958523b97f7", wtxid.ToHexString()); Assert.Equal((uint)295, tx.GetSize()); Assert.Equal((uint)213, tx.GetVsize()); Assert.Equal((uint)850, tx.GetWeight()); Assert.Equal((uint)2, tx.GetVersion()); Assert.Equal((uint)0, tx.GetLockTime()); Assert.Equal((uint)2, tx.GetTxInCount()); Assert.Equal((uint)3, tx.GetTxOutCount()); Assert.Equal((uint)1, tx.GetTxInIndex(outpoint2)); Assert.Equal((uint)2, tx.GetTxOutIndex(addr3)); Assert.Equal((uint)1, tx.GetTxOutIndex(addr2.GetLockingScript())); Assert.True(outpoint2.Equals(tx.GetTxIn(outpoint2).OutPoint)); Assert.True(outpoint2.Equals(tx.GetTxIn(1).OutPoint)); Assert.True(outpoint2.Equals(tx.GetTxInList()[1].OutPoint)); Assert.True(addr2.GetLockingScript().Equals(tx.GetTxOut(addr2).ScriptPubkey)); Assert.True(addr2.GetLockingScript().Equals(tx.GetTxOut(addr2.GetLockingScript()).ScriptPubkey)); Assert.True(addr2.GetLockingScript().Equals(tx.GetTxOut(1).ScriptPubkey)); Assert.True(addr2.GetLockingScript().Equals(tx.GetTxOutList()[1].ScriptPubkey)); }
public void EmptyConstructorTest() { Txid txid = new Txid(); Assert.Equal("0000000000000000000000000000000000000000000000000000000000000000", txid.ToHexString()); OutPoint outpoint1 = new OutPoint(); OutPoint outpoint2 = new OutPoint(txid.GetBytes(), 0); Assert.False((outpoint1 != outpoint2)); }