Java Code Examples for org.bitcoinj.crypto.TransactionSignature#dummy()
The following examples show how to use
org.bitcoinj.crypto.TransactionSignature#dummy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptTest.java From bcm-android with GNU General Public License v3.0 | 4 votes |
@Test public void createAndUpdateEmptyInputScript() throws Exception { TransactionSignature dummySig = TransactionSignature.dummy(); ECKey key = new ECKey(); // P2PK Script inputScript = ScriptBuilder.createInputScript(dummySig); assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin())); inputScript = ScriptBuilder.createInputScript(null); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); // P2PKH inputScript = ScriptBuilder.createInputScript(dummySig, key); assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin())); inputScript = ScriptBuilder.createInputScript(null, key); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(key.getPubKey())); // P2SH ECKey key2 = new ECKey(); Script multisigScript = ScriptBuilder.createMultiSigOutputScript(2, Arrays.asList(key, key2)); inputScript = ScriptBuilder.createP2SHMultiSigInputScript(Arrays.asList(dummySig, dummySig), multisigScript); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); inputScript = ScriptBuilder.createP2SHMultiSigInputScript(null, multisigScript); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(2).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 0, 1, 1); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(2).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 1, 1, 1); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); // updating scriptSig with no missing signatures try { ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 1, 1, 1); fail("Exception expected"); } catch (Exception e) { assertEquals(IllegalArgumentException.class, e.getClass()); } }
Example 2
Source File: ScriptTest.java From green_android with GNU General Public License v3.0 | 4 votes |
@Test public void createAndUpdateEmptyInputScript() throws Exception { TransactionSignature dummySig = TransactionSignature.dummy(); ECKey key = new ECKey(); // pay-to-pubkey Script inputScript = ScriptBuilder.createInputScript(dummySig); assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin())); inputScript = ScriptBuilder.createInputScript(null); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); // pay-to-address inputScript = ScriptBuilder.createInputScript(dummySig, key); assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin())); inputScript = ScriptBuilder.createInputScript(null, key); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(key.getPubKey())); // pay-to-script-hash ECKey key2 = new ECKey(); Script multisigScript = ScriptBuilder.createMultiSigOutputScript(2, Arrays.asList(key, key2)); inputScript = ScriptBuilder.createP2SHMultiSigInputScript(Arrays.asList(dummySig, dummySig), multisigScript); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); inputScript = ScriptBuilder.createP2SHMultiSigInputScript(null, multisigScript); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(2).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 0, 1, 1); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(2).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 1, 1, 1); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); // updating scriptSig with no missing signatures try { ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 1, 1, 1); fail("Exception expected"); } catch (Exception e) { assertEquals(IllegalArgumentException.class, e.getClass()); } }
Example 3
Source File: ScriptTest.java From GreenBits with GNU General Public License v3.0 | 4 votes |
@Test public void createAndUpdateEmptyInputScript() throws Exception { TransactionSignature dummySig = TransactionSignature.dummy(); ECKey key = new ECKey(); // pay-to-pubkey Script inputScript = ScriptBuilder.createInputScript(dummySig); assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin())); inputScript = ScriptBuilder.createInputScript(null); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); // pay-to-address inputScript = ScriptBuilder.createInputScript(dummySig, key); assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin())); inputScript = ScriptBuilder.createInputScript(null, key); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(key.getPubKey())); // pay-to-script-hash ECKey key2 = new ECKey(); Script multisigScript = ScriptBuilder.createMultiSigOutputScript(2, Arrays.asList(key, key2)); inputScript = ScriptBuilder.createP2SHMultiSigInputScript(Arrays.asList(dummySig, dummySig), multisigScript); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); inputScript = ScriptBuilder.createP2SHMultiSigInputScript(null, multisigScript); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(2).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 0, 1, 1); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(2).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 1, 1, 1); assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0)); assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin())); assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram())); // updating scriptSig with no missing signatures try { ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 1, 1, 1); fail("Exception expected"); } catch (Exception e) { assertEquals(IllegalArgumentException.class, e.getClass()); } }