1
- package com .strategyobject .substrateclient .rpc . sections ;
1
+ package com .strategyobject .substrateclient .api . rpc ;
2
2
3
+ import com .strategyobject .substrateclient .api .rpc .substitutes .BalanceTransfer ;
4
+ import com .strategyobject .substrateclient .common .types .Size ;
3
5
import com .strategyobject .substrateclient .common .utils .HexConverter ;
4
- import com .strategyobject .substrateclient .crypto .KeyRing ;
5
- import com .strategyobject .substrateclient .rpc .core .RpcGeneratedSectionFactory ;
6
- import com .strategyobject .substrateclient .rpc .core .RpcInterfaceInitializationException ;
7
- import com .strategyobject .substrateclient .rpc .sections .substitutes .BalanceTransfer ;
8
- import com .strategyobject .substrateclient .rpc .types .*;
6
+ import com .strategyobject .substrateclient .crypto .*;
7
+ import com .strategyobject .substrateclient .rpc .RpcGeneratedSectionFactory ;
9
8
import com .strategyobject .substrateclient .tests .containers .SubstrateVersion ;
10
9
import com .strategyobject .substrateclient .tests .containers .TestSubstrateContainer ;
11
10
import com .strategyobject .substrateclient .transport .ws .WsProvider ;
12
- import com .strategyobject .substrateclient .types .KeyPair ;
13
- import com .strategyobject .substrateclient .types .PublicKey ;
14
- import com .strategyobject .substrateclient .types .Signable ;
11
+ import com .strategyobject .substrateclient .types .*;
15
12
import lombok .val ;
16
13
import lombok .var ;
17
- import org .bouncycastle . crypto . digests . Blake2bDigest ;
14
+ import org .junit . jupiter . api . Assertions ;
18
15
import org .junit .jupiter .api .Test ;
19
16
import org .testcontainers .containers .Network ;
20
17
import org .testcontainers .junit .jupiter .Container ;
27
24
import java .util .concurrent .atomic .AtomicInteger ;
28
25
import java .util .concurrent .atomic .AtomicReference ;
29
26
27
+ import static org .junit .jupiter .api .Assertions .*;
30
28
import static org .awaitility .Awaitility .await ;
31
29
import static org .hamcrest .Matchers .greaterThan ;
32
- import static org .junit .jupiter .api .Assertions .*;
33
30
34
31
@ Testcontainers
35
- public class AuthorTests {
32
+ class AuthorTests {
36
33
private static final int WAIT_TIMEOUT = 10 ;
37
34
private static final Network network = Network .newNetwork ();
38
35
private static final AtomicInteger NONCE = new AtomicInteger (0 );
@@ -41,17 +38,8 @@ public class AuthorTests {
41
38
static final TestSubstrateContainer substrate = new TestSubstrateContainer (SubstrateVersion .V3_0_0 )
42
39
.withNetwork (network );
43
40
44
- private static byte [] blake2 (byte [] value ) {
45
- val digest = new Blake2bDigest (256 );
46
- digest .update (value , 0 , value .length );
47
-
48
- val result = new byte [32 ];
49
- digest .doFinal (result , 0 );
50
- return result ;
51
- }
52
-
53
41
@ Test
54
- void hasKey () throws ExecutionException , InterruptedException , TimeoutException , RpcInterfaceInitializationException {
42
+ void hasKey () throws ExecutionException , InterruptedException , TimeoutException {
55
43
try (WsProvider wsProvider = WsProvider .builder ()
56
44
.setEndpoint (substrate .getWsAddress ())
57
45
.disableAutoConnect ()
@@ -75,7 +63,7 @@ void hasKey() throws ExecutionException, InterruptedException, TimeoutException,
75
63
}
76
64
77
65
@ Test
78
- void insertKey () throws ExecutionException , InterruptedException , TimeoutException , RpcInterfaceInitializationException {
66
+ void insertKey () throws ExecutionException , InterruptedException , TimeoutException {
79
67
try (WsProvider wsProvider = WsProvider .builder ()
80
68
.setEndpoint (substrate .getWsAddress ())
81
69
.disableAutoConnect ()
@@ -84,7 +72,7 @@ void insertKey() throws ExecutionException, InterruptedException, TimeoutExcepti
84
72
85
73
Author rpcSection = RpcGeneratedSectionFactory .create (Author .class , wsProvider );
86
74
87
- assertDoesNotThrow (() -> rpcSection .insertKey ("aura" ,
75
+ Assertions . assertDoesNotThrow (() -> rpcSection .insertKey ("aura" ,
88
76
"alice" ,
89
77
PublicKey .fromBytes (
90
78
HexConverter .toBytes ("0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" )))
@@ -93,7 +81,7 @@ void insertKey() throws ExecutionException, InterruptedException, TimeoutExcepti
93
81
}
94
82
95
83
@ Test
96
- void submitExtrinsic () throws ExecutionException , InterruptedException , TimeoutException , RpcInterfaceInitializationException {
84
+ void submitExtrinsic () throws ExecutionException , InterruptedException , TimeoutException {
97
85
try (WsProvider wsProvider = WsProvider .builder ()
98
86
.setEndpoint (substrate .getWsAddress ())
99
87
.disableAutoConnect ()
@@ -105,13 +93,13 @@ void submitExtrinsic() throws ExecutionException, InterruptedException, TimeoutE
105
93
val genesis = chainSection .getBlockHash (0 ).get (WAIT_TIMEOUT , TimeUnit .SECONDS );
106
94
Author authorSection = RpcGeneratedSectionFactory .create (Author .class , wsProvider );
107
95
108
- assertDoesNotThrow (() -> authorSection .submitExtrinsic (createBalanceTransferExtrinsic (genesis , NONCE .getAndIncrement ()))
96
+ Assertions . assertDoesNotThrow (() -> authorSection .submitExtrinsic (createBalanceTransferExtrinsic (genesis , NONCE .getAndIncrement ()))
109
97
.get (WAIT_TIMEOUT , TimeUnit .SECONDS ));
110
98
}
111
99
}
112
100
113
101
@ Test
114
- void submitAndWatchExtrinsic () throws ExecutionException , InterruptedException , TimeoutException , RpcInterfaceInitializationException {
102
+ void submitAndWatchExtrinsic () throws ExecutionException , InterruptedException , TimeoutException {
115
103
try (WsProvider wsProvider = WsProvider .builder ()
116
104
.setEndpoint (substrate .getWsAddress ())
117
105
.disableAutoConnect ()
@@ -169,7 +157,7 @@ void submitAndWatchExtrinsic() throws ExecutionException, InterruptedException,
169
157
170
158
private Signature sign (KeyRing keyRing , Signable payload ) {
171
159
var signed = payload .getBytes ();
172
- val signature = signed .length > 256 ? blake2 (signed ) : signed ;
160
+ val signature = signed .length > 256 ? Hasher . blake2 (Size . of256 , signed ) : signed ;
173
161
174
162
return Sr25519Signature .from (keyRing .sign (() -> signature ));
175
163
}
0 commit comments