Java Code Examples for org.bitcoinj.core.Coin#CENT

The following examples show how to use org.bitcoinj.core.Coin#CENT . 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: PaymentChannelServerTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldAllowExactTimeWindow() {
    final TwoWayChannelMessage message = createClientVersionMessage();
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));
    replay(connection);
    final int expire = 24 * 60 * 60 - 60;  // This the default defined in paymentchannel.proto

    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){
        @Override
        public long getMaxTimeWindow() { return expire; }
        @Override
        public long getMinTimeWindow() { return expire; }
    }, connection);
    dut.connectionOpen();
    long expectedExpire = Utils.currentTimeSeconds() + expire;
    dut.receiveMessage(message);

    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 2
Source File: PaymentChannelServerTest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldAllowExactTimeWindow() {
    final TwoWayChannelMessage message = createClientVersionMessage();
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));
    replay(connection);
    final int expire = 24 * 60 * 60 - 60;  // This the default defined in paymentchannel.proto

    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties() {
        @Override
        public long getMaxTimeWindow() {
            return expire;
        }

        @Override
        public long getMinTimeWindow() {
            return expire;
        }
    }, connection);
    dut.connectionOpen();
    long expectedExpire = Utils.currentTimeSeconds() + expire;
    dut.receiveMessage(message);

    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 3
Source File: PaymentChannelServerTest.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldAcceptDefaultTimeWindow() {
    final TwoWayChannelMessage message = createClientVersionMessage();
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));
    replay(connection);

    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, connection);

    dut.connectionOpen();
    dut.receiveMessage(message);

    long expectedExpire = Utils.currentTimeSeconds() + 24 * 60 * 60 - 60;  // This the default defined in paymentchannel.proto
    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 4
Source File: PaymentChannelServerTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldTruncateTooLargeTimeWindow() {
    final int maxTimeWindow = 40000;
    final int timeWindow = maxTimeWindow + 1;
    final TwoWayChannelMessage message = createClientVersionMessage(timeWindow);
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));
    replay(connection);

    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){
        @Override
        public long getMaxTimeWindow() {
            return maxTimeWindow;
        }
        @Override
        public long getMinTimeWindow() { return 20000; }
    }, connection);

    dut.connectionOpen();
    dut.receiveMessage(message);

    long expectedExpire = Utils.currentTimeSeconds() + maxTimeWindow;
    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 5
Source File: PaymentChannelServerTest.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldTruncateTooLargeTimeWindow() {
    final int maxTimeWindow = 40000;
    final int timeWindow = maxTimeWindow + 1;
    final TwoWayChannelMessage message = createClientVersionMessage(timeWindow);
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));
    replay(connection);

    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){
        @Override
        public long getMaxTimeWindow() {
            return maxTimeWindow;
        }
        @Override
        public long getMinTimeWindow() { return 20000; }
    }, connection);

    dut.connectionOpen();
    dut.receiveMessage(message);

    long expectedExpire = Utils.currentTimeSeconds() + maxTimeWindow;
    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 6
Source File: PaymentChannelServerTest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldAcceptDefaultTimeWindow() {
    final TwoWayChannelMessage message = createClientVersionMessage();
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));
    replay(connection);

    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, connection);

    dut.connectionOpen();
    dut.receiveMessage(message);

    long expectedExpire = Utils.currentTimeSeconds() + 24 * 60 * 60 - 60;  // This the default defined in paymentchannel.proto
    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 7
Source File: PaymentChannelServerTest.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldAllowExactTimeWindow() {
    final TwoWayChannelMessage message = createClientVersionMessage();
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));
    replay(connection);
    final int expire = 24 * 60 * 60 - 60;  // This the default defined in paymentchannel.proto

    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){
        @Override
        public long getMaxTimeWindow() { return expire; }
        @Override
        public long getMinTimeWindow() { return expire; }
    }, connection);
    dut.connectionOpen();
    long expectedExpire = Utils.currentTimeSeconds() + expire;
    dut.receiveMessage(message);

    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 8
Source File: PaymentChannelServerTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldAcceptDefaultTimeWindow() {
    final TwoWayChannelMessage message = createClientVersionMessage();
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));
    replay(connection);

    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, connection);

    dut.connectionOpen();
    dut.receiveMessage(message);

    long expectedExpire = Utils.currentTimeSeconds() + 24 * 60 * 60 - 60;  // This the default defined in paymentchannel.proto
    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 9
Source File: PaymentChannelServerTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowTimeWindowLessThan2h() {
    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){
        @Override
        public long getMaxTimeWindow() { return 40000; }
        @Override
        public long getMinTimeWindow() {
            return 7199;
        }
    }, connection);
}
 
Example 10
Source File: TXUtil.java    From jelectrum with MIT License 5 votes vote down vote up
public ByteString getScriptHashForAddress(String str)
{
  Address addr = Address.fromString(params, str);
  Transaction tx= new Transaction(params);

  TransactionOutput tx_out = new TransactionOutput(params, tx, Coin.CENT, addr);

  return getScriptHashForOutput(tx_out);
}
 
Example 11
Source File: PaymentChannelServerTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowNegativeTimeWindow() {
    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){
        @Override
        public long getMaxTimeWindow() { return 40000; }
        @Override
        public long getMinTimeWindow() { return 40001; }
    }, connection);
}
 
Example 12
Source File: PaymentChannelServerTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowTimeWindowLessThan2h() {
    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){
        @Override
        public long getMaxTimeWindow() { return 40000; }
        @Override
        public long getMinTimeWindow() {
            return 7199;
        }
    }, connection);
}
 
Example 13
Source File: PaymentChannelServerTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldTruncateTooSmallTimeWindow() {
    final int minTimeWindow = 20000;
    final int timeWindow = minTimeWindow - 1;
    final TwoWayChannelMessage message = createClientVersionMessage(timeWindow);
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));

    replay(connection);
    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties() {
        @Override
        public long getMinTimeWindow() {
            return minTimeWindow;
        }
        @Override
        public long getMaxTimeWindow() {
            return 40000;
        }
    }, connection);

    dut.connectionOpen();
    dut.receiveMessage(message);

    long expectedExpire = Utils.currentTimeSeconds() + minTimeWindow;
    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 14
Source File: PaymentChannelServerTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowNegativeTimeWindow() {
    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){
        @Override
        public long getMaxTimeWindow() { return 40000; }
        @Override
        public long getMinTimeWindow() { return 40001; }
    }, connection);
}
 
Example 15
Source File: PaymentChannelServerTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldTruncateTooSmallTimeWindow() {
    final int minTimeWindow = 20000;
    final int timeWindow = minTimeWindow - 1;
    final TwoWayChannelMessage message = createClientVersionMessage(timeWindow);
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));

    replay(connection);
    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties() {
        @Override
        public long getMinTimeWindow() {
            return minTimeWindow;
        }
        @Override
        public long getMaxTimeWindow() {
            return 40000;
        }
    }, connection);

    dut.connectionOpen();
    dut.receiveMessage(message);

    long expectedExpire = Utils.currentTimeSeconds() + minTimeWindow;
    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 16
Source File: PaymentChannelServerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowNegativeTimeWindow() {
    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties() {
        @Override
        public long getMaxTimeWindow() {
            return 40000;
        }

        @Override
        public long getMinTimeWindow() {
            return 40001;
        }
    }, connection);
}
 
Example 17
Source File: PaymentChannelServerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowTimeWindowLessThan2h() {
    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties() {
        @Override
        public long getMaxTimeWindow() {
            return 40000;
        }

        @Override
        public long getMinTimeWindow() {
            return 7199;
        }
    }, connection);
}
 
Example 18
Source File: PaymentChannelServerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldTruncateTooLargeTimeWindow() {
    final int maxTimeWindow = 40000;
    final int timeWindow = maxTimeWindow + 1;
    final TwoWayChannelMessage message = createClientVersionMessage(timeWindow);
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));
    replay(connection);

    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties() {
        @Override
        public long getMaxTimeWindow() {
            return maxTimeWindow;
        }

        @Override
        public long getMinTimeWindow() {
            return 20000;
        }
    }, connection);

    dut.connectionOpen();
    dut.receiveMessage(message);

    long expectedExpire = Utils.currentTimeSeconds() + maxTimeWindow;
    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}
 
Example 19
Source File: PaymentChannelServerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldTruncateTooSmallTimeWindow() {
    final int minTimeWindow = 20000;
    final int timeWindow = minTimeWindow - 1;
    final TwoWayChannelMessage message = createClientVersionMessage(timeWindow);
    final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
    connection.sendToClient(capture(initiateCapture));

    replay(connection);
    dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties() {
        @Override
        public long getMinTimeWindow() {
            return minTimeWindow;
        }

        @Override
        public long getMaxTimeWindow() {
            return 40000;
        }
    }, connection);

    dut.connectionOpen();
    dut.receiveMessage(message);

    long expectedExpire = Utils.currentTimeSeconds() + minTimeWindow;
    assertServerVersion();
    assertExpireTime(expectedExpire, initiateCapture);
}