Skip to content

Commit

Permalink
WalletProtobufSerializer: Fix protobuf serialization of large sequenc…
Browse files Browse the repository at this point in the history
…e numbers.
  • Loading branch information
schildbach committed Mar 23, 2016
1 parent 3b562b5 commit 69da6f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Expand Up @@ -572,9 +572,8 @@ private void readTransaction(Protos.Transaction txProto, NetworkParameters param
);
Coin value = inputProto.hasValue() ? Coin.valueOf(inputProto.getValue()) : null;
TransactionInput input = new TransactionInput(params, tx, scriptBytes, outpoint, value);
if (inputProto.hasSequence()) {
input.setSequenceNumber(inputProto.getSequence());
}
if (inputProto.hasSequence())
input.setSequenceNumber(0xffffffffL & inputProto.getSequence());
tx.addInput(input);
}

Expand Down
Expand Up @@ -51,6 +51,7 @@
import static org.bitcoinj.core.Coin.*;
import static org.bitcoinj.testing.FakeTxBuilder.createFakeTx;
import static org.junit.Assert.*;
import static com.google.common.base.Preconditions.checkNotNull;

public class WalletProtobufSerializerTest {
static final NetworkParameters params = UnitTestParams.get();
Expand Down Expand Up @@ -205,6 +206,22 @@ public void testLastBlockSeenHash() throws Exception {
assertEquals(genesisBlock.getHash(), wallet2.getLastBlockSeenHash());
}

@Test
public void testSequenceNumber() throws Exception {
Wallet wallet = new Wallet(params);
Transaction tx1 = createFakeTx(params, Coin.COIN, wallet.currentReceiveAddress());
tx1.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE);
wallet.receivePending(tx1, null);
Transaction tx2 = createFakeTx(params, Coin.COIN, wallet.currentReceiveAddress());
tx2.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE - 1);
wallet.receivePending(tx2, null);
Wallet walletCopy = roundTrip(wallet);
Transaction tx1copy = checkNotNull(walletCopy.getTransaction(tx1.getHash()));
assertEquals(TransactionInput.NO_SEQUENCE, tx1copy.getInput(0).getSequenceNumber());
Transaction tx2copy = checkNotNull(walletCopy.getTransaction(tx2.getHash()));
assertEquals(TransactionInput.NO_SEQUENCE - 1, tx2copy.getInput(0).getSequenceNumber());
}

@Test
public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception {
// Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.
Expand Down

0 comments on commit 69da6f8

Please sign in to comment.