3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-14 11:15:51 +00:00

Adds one test to the CHECKMULTISIG feature which was failing before

This commit is contained in:
Wojciech Langiewicz 2014-11-10 21:45:55 +01:00
parent b279c40801
commit aafb15a24f
2 changed files with 71 additions and 2 deletions

View File

@ -0,0 +1,69 @@
package org.bitcoinj.core;
import com.google.common.collect.ImmutableList;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.script.ScriptOpCodes;
import org.bitcoinj.testing.TestWithWallet;
import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class TransactionOutputTest extends TestWithWallet {
@Before
public void setUp() throws Exception {
super.setUp();
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
@Test
public void testMultiSigOutputToString() throws Exception {
sendMoneyToWallet(Coin.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
ECKey myKey = new ECKey();
this.wallet.importKey(myKey);
// Simulate another signatory
ECKey otherKey = new ECKey();
// Create multi-sig transaction
Transaction multiSigTransaction = new Transaction(params);
ImmutableList<ECKey> keys = ImmutableList.of(myKey, otherKey);
Script scriptPubKey = ScriptBuilder.createMultiSigOutputScript(2, keys);
multiSigTransaction.addOutput(Coin.COIN, scriptPubKey);
Wallet.SendRequest req = Wallet.SendRequest.forTx(multiSigTransaction);
this.wallet.completeTx(req);
TransactionOutput multiSigTransactionOutput = multiSigTransaction.getOutput(0);
assertThat(multiSigTransactionOutput.toString(), CoreMatchers.containsString("CHECKMULTISIG"));
}
@Test
public void testP2SHOutputScript() throws Exception {
String P2SHAddressString = "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU";
Address P2SHAddress = new Address(MainNetParams.get(), P2SHAddressString);
Script script = ScriptBuilder.createOutputScript(P2SHAddress);
Transaction tx = new Transaction(MainNetParams.get());
tx.addOutput(Coin.COIN, script);
assertEquals(P2SHAddressString, tx.getOutput(0).getAddressFromP2SH(MainNetParams.get()).toString());
}
@Test
public void getAddressTests() throws Exception {
Transaction tx = new Transaction(MainNetParams.get());
Script script = new ScriptBuilder().op(ScriptOpCodes.OP_RETURN).data("hello world!".getBytes()).build();
tx.addOutput(Coin.CENT, script);
assertNull(tx.getOutput(0).getAddressFromP2SH(params));
assertNull(tx.getOutput(0).getAddressFromP2PKHScript(params));
}
}

View File

@ -102,8 +102,8 @@ public class ScriptTest {
@Test
public void testP2SHOutputScript() throws Exception {
Address p2shAddress = new Address(MainNetParams.get(), "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
assertTrue(ScriptBuilder.createOutputScript(p2shAddress).isPayToScriptHash());
Address p2shAddress = new Address(MainNetParams.get(), "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
assertTrue(ScriptBuilder.createOutputScript(p2shAddress).isPayToScriptHash());
}
@Test