File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package bitcoin .test ;
2+
3+ import bitcoin .base .BitcoinRpcPolicy ;
4+
5+ /** Deterministic, dependency-free regression checks for Bitcoin input policy. */
6+ public final class BitcoinRpcPolicyTest
7+ {
8+ public static void main (final String [] args )
9+ {
10+ assertEquals (100000000L , BitcoinRpcPolicy .requireSatoshis ("1" ));
11+ assertEquals (1L , BitcoinRpcPolicy .requireSatoshis ("0.00000001" ));
12+ assertEquals (123456789L , BitcoinRpcPolicy .requireSatoshis ("1.23456789" ));
13+ assertRejected ("0" );
14+ assertRejected ("-1" );
15+ assertRejected ("0.000000001" );
16+ assertRejected ("not-a-number" );
17+ assertRejected ("92233720368" );
18+ if (!BitcoinRpcPolicy .isAllowed ("getbalance" )) throw new AssertionError ("getbalance must be allowed" );
19+ if (BitcoinRpcPolicy .isAllowed ("importprivkey" )) throw new AssertionError ("importprivkey must remain outside the server RPC surface" );
20+ BitcoinRpcPolicy .requireAddress ("bcrt1qexampleaddressmuststillfail" );
21+ }
22+
23+ private static void assertRejected (final String value )
24+ {
25+ try
26+ {
27+ BitcoinRpcPolicy .requireSatoshis (value );
28+ throw new AssertionError ("Expected rejection: " + value );
29+ }
30+ catch (IllegalArgumentException expected ) { }
31+ }
32+
33+ private static void assertEquals (final long expected , final long actual )
34+ {
35+ if (expected != actual ) throw new AssertionError ("Expected " + expected + " but got " + actual );
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments