mirror of
https://github.com/sparrowwallet/drongo.git
synced 2025-11-05 11:56:38 +00:00
add silent payment change tests
This commit is contained in:
parent
9c826d7819
commit
7f707017b7
2 changed files with 32 additions and 0 deletions
|
|
@ -49,6 +49,18 @@ public class SilentPaymentScanAddressTest {
|
|||
Assertions.assertEquals("sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq7c2zfthc6x3a5yecwc52nxa0kfd20xuz08zyrjpfw4l2j257yq6qgnkdh5", unlabelled.getLabelledAddress(1001337).getAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChange() {
|
||||
ECKey scanPrivateKey = ECKey.fromPrivate(Utils.hexToBytes("11b7a82e06ca2648d5fded2366478078ec4fc9dc1d8ff487518226f229d768fd"));
|
||||
ECKey spendPrivateKey = ECKey.fromPrivate(Utils.hexToBytes("b8f87388cbb41934c50daca018901b00070a5ff6cc25a7e9e716a9d5b9e4d664"));
|
||||
|
||||
SilentPaymentScanAddress unlabelled = SilentPaymentScanAddress.from(scanPrivateKey, ECKey.fromPublicOnly(spendPrivateKey));
|
||||
Assertions.assertEquals("sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqauj52ymtc4xdkmx3tgyhrsemg2g3303xk2gtzfy8h8ejet8fz8jcw23zua", unlabelled.getAddress());
|
||||
Assertions.assertEquals("sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqlv6saelkk5snl4wfutyxrchpzzwm8rjp3z6q7apna59z9huq4x754e5atr", unlabelled.getChangeAddress().getAddress());
|
||||
Assertions.assertEquals("03bc95144daf15336db3456825c70ced0a4462f89aca42c4921ee7ccb2b3a44796", Utils.bytesToHex(spendPrivateKey.getPubKey()));
|
||||
Assertions.assertEquals("03ecd43b9fdad484ff57278b21878b844276ce390622d03dd0cfb4288b7e02a6f5", Utils.bytesToHex(unlabelled.getChangeAddress().getSpendKey().getPubKey()));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
Network.set(null);
|
||||
|
|
|
|||
|
|
@ -55,6 +55,26 @@ public class SilentPaymentUtilsTest {
|
|||
Assertions.assertEquals("024ac253c216532e961988e2a8ce266a447c894c781e52ef6cee902361db960004", Utils.bytesToHex(tweak));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTweakChange() {
|
||||
Transaction transaction = new Transaction();
|
||||
transaction.addInput(Sha256Hash.wrap("f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16"), 0, new Script(Utils.hexToBytes("483046022100ad79e6801dd9a8727f342f31c71c4912866f59dc6e7981878e92c5844a0ce929022100fb0d2393e813968648b9753b7e9871d90ab3d815ebf91820d704b19f4ed224d621025a1e61f898173040e20616d43e9f496fba90338a39faa1ed98fcbaeee4dd9be5")));
|
||||
transaction.addInput(Sha256Hash.wrap("a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d"), 0, new Script(Utils.hexToBytes("473045022100a8c61b2d470e393279d1ba54f254b7c237de299580b7fa01ffcc940442ecec4502201afba952f4e4661c40acde7acc0341589031ba103a307b886eb867b23b850b972103782eeb913431ca6e9b8c2fd80a5f72ed2024ef72a3c6fb10263c379937323338")));
|
||||
transaction.addOutput(1000L, ScriptType.P2TR.getOutputScript(ECKey.fromPublicOnly(Utils.hexToBytes("be368e28979d950245d742891ae6064020ba548c1e2e65a639a8bb0675d95cff"))));
|
||||
|
||||
Map<HashIndex, Script> spentScriptPubKeys = new HashMap<>();
|
||||
HashIndex hashIndex0 = new HashIndex(transaction.getInputs().getFirst().getOutpoint().getHash(), transaction.getInputs().getFirst().getOutpoint().getIndex());
|
||||
Script spentScriptPubKey0 = new Script(Utils.hexToBytes("76a91419c2f3ae0ca3b642bd3e49598b8da89f50c1416188ac"));
|
||||
HashIndex hashIndex1 = new HashIndex(transaction.getInputs().getLast().getOutpoint().getHash(), transaction.getInputs().getLast().getOutpoint().getIndex());
|
||||
Script spentScriptPubKey1 = new Script(Utils.hexToBytes("76a9147cdd63cc408564188e8e472640e921c7c90e651d88ac"));
|
||||
spentScriptPubKeys.put(hashIndex0, spentScriptPubKey0);
|
||||
spentScriptPubKeys.put(hashIndex1, spentScriptPubKey1);
|
||||
|
||||
byte[] tweak = SilentPaymentUtils.getTweak(transaction, spentScriptPubKeys);
|
||||
Assertions.assertNotNull(tweak);
|
||||
Assertions.assertEquals("0314bec14463d6c0181083d607fecfba67bb83f95915f6f247975ec566d5642ee8", Utils.bytesToHex(tweak));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidOutput() {
|
||||
Transaction transaction = new Transaction();
|
||||
|
|
|
|||
Loading…
Reference in a new issue