@@ -28,6 +28,7 @@ import (
28
28
29
29
"github.com/google/uuid"
30
30
"github.com/hyperledger/firefly-signer/pkg/abi"
31
+ "github.com/kaleido-io/paladin/config/pkg/confutil"
31
32
"github.com/kaleido-io/paladin/core/componenttest/domains"
32
33
"github.com/kaleido-io/paladin/core/pkg/blockindexer"
33
34
"github.com/kaleido-io/paladin/core/pkg/persistence"
@@ -46,11 +47,10 @@ import (
46
47
)
47
48
48
49
func TestRunSimpleStorageEthTransaction (t * testing.T ) {
49
- //TODO refactor this to be more black box by using JSONRPC interface to invoke the public contract
50
50
ctx := context .Background ()
51
51
logrus .SetLevel (logrus .DebugLevel )
52
52
53
- instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil )
53
+ instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil , false )
54
54
cm := instance .cm
55
55
c := pldclient .Wrap (instance .client ).ReceiptPollingInterval (250 * time .Millisecond )
56
56
@@ -122,6 +122,132 @@ func TestRunSimpleStorageEthTransaction(t *testing.T) {
122
122
123
123
}
124
124
125
+ func TestUpdatePublicTransaction (t * testing.T ) {
126
+ ctx := context .Background ()
127
+ logrus .SetLevel (logrus .DebugLevel )
128
+
129
+ instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil , true )
130
+ c := pldclient .Wrap (instance .client ).ReceiptPollingInterval (250 * time .Millisecond )
131
+
132
+ // set up the receipt listener
133
+ success , err := c .PTX ().CreateReceiptListener (ctx , & pldapi.TransactionReceiptListener {
134
+ Name : "listener1" ,
135
+ })
136
+ require .NoError (t , err )
137
+ require .True (t , success )
138
+
139
+ wsClient , err := c .WebSocket (ctx , instance .wsConfig )
140
+ require .NoError (t , err )
141
+
142
+ sub , err := wsClient .PTX ().SubscribeReceipts (ctx , "listener1" )
143
+ require .NoError (t , err )
144
+
145
+ build , err := solutils .LoadBuild (ctx , simpleStorageBuildJSON )
146
+ require .NoError (t , err )
147
+
148
+ simpleStorage := c .ForABI (ctx , build .ABI ).Public ().From ("key1" )
149
+
150
+ res := simpleStorage .Clone ().
151
+ Constructor ().
152
+ Bytecode (build .Bytecode ).
153
+ Inputs (`{"x":11223344}` ).
154
+ Send ()
155
+ require .NoError (t , res .Error ())
156
+
157
+ var deployReceipt * pldapi.TransactionReceiptFull
158
+
159
+ for deployReceipt == nil {
160
+ subNotification , ok := <- sub .Notifications ()
161
+ if ok {
162
+ var batch pldapi.TransactionReceiptBatch
163
+ _ = json .Unmarshal (subNotification .GetResult (), & batch )
164
+ for _ , r := range batch .Receipts {
165
+ if * res .ID () == r .ID {
166
+ deployReceipt = r
167
+ }
168
+ }
169
+ err := subNotification .Ack (ctx )
170
+ require .NoError (t , err )
171
+ }
172
+ }
173
+
174
+ tx , err := c .PTX ().GetTransactionFull (ctx , * res .ID ())
175
+ require .NoError (t , err )
176
+ contractAddr := tx .Receipt .ContractAddress
177
+
178
+ setRes := simpleStorage .Clone ().
179
+ Function ("set" ).
180
+ To (contractAddr ).
181
+ Inputs (`{"_x":99887766}` ).
182
+ PublicTxOptions (pldapi.PublicTxOptions {
183
+ // gas is set below instrinsic limit
184
+ Gas : confutil .P (tktypes .HexUint64 (1 )),
185
+ }).
186
+ Send ()
187
+ require .NoError (t , setRes .Error ())
188
+ require .NotNil (t , setRes .ID ())
189
+
190
+ // wait for the submission to be tried and to fail
191
+ time .Sleep (2 * time .Second )
192
+
193
+ tx , err = c .PTX ().GetTransactionFull (ctx , * setRes .ID ())
194
+ require .NoError (t , err )
195
+ require .Len (t , tx .Public , 1 )
196
+ require .NotNil (t , tx .Public [0 ].Activity [0 ])
197
+ assert .Regexp (t , "ERROR.*Intrinsic" , tx .Public [0 ].Activity [0 ])
198
+
199
+ _ , err = c .PTX ().UpdateTransaction (ctx , * setRes .ID (), & pldapi.TransactionInput {
200
+ TransactionBase : pldapi.TransactionBase {
201
+ From : "key1" ,
202
+ Function : "set" ,
203
+ Data : tktypes .RawJSON (`{"_x":99887766}` ),
204
+ To : contractAddr ,
205
+ ABIReference : tx .ABIReference ,
206
+ PublicTxOptions : pldapi.PublicTxOptions {
207
+ Gas : confutil .P (tktypes .HexUint64 (10000000 )),
208
+ },
209
+ },
210
+ })
211
+ require .NoError (t , err )
212
+
213
+ var setReceipt * pldapi.TransactionReceiptFull
214
+ for setReceipt == nil {
215
+ subNotification , ok := <- sub .Notifications ()
216
+ if ok {
217
+ var batch pldapi.TransactionReceiptBatch
218
+ _ = json .Unmarshal (subNotification .GetResult (), & batch )
219
+ for _ , r := range batch .Receipts {
220
+ if * setRes .ID () == r .ID {
221
+ setReceipt = r
222
+ }
223
+ }
224
+ err := subNotification .Ack (ctx )
225
+ require .NoError (t , err )
226
+ }
227
+
228
+ }
229
+
230
+ tx , err = c .PTX ().GetTransactionFull (ctx , * setRes .ID ())
231
+ require .NoError (t , err )
232
+ require .NotNil (t , tx .Receipt )
233
+ require .True (t , tx .Receipt .Success )
234
+ require .Len (t , tx .Public , 1 )
235
+ assert .Equal (t , tx .Public [0 ].Submissions [0 ].TransactionHash .HexString (), setReceipt .TransactionHash .HexString ())
236
+ assert .Len (t , tx .History , 2 )
237
+
238
+ // try to update the transaction again- it should fail now it is complete
239
+ _ , err = c .PTX ().UpdateTransaction (ctx , * setRes .ID (), & pldapi.TransactionInput {
240
+ TransactionBase : pldapi.TransactionBase {
241
+ From : "key1" ,
242
+ Function : "set" ,
243
+ Data : tktypes .RawJSON (`{"_x":99887765}` ),
244
+ To : contractAddr ,
245
+ ABIReference : tx .ABIReference ,
246
+ },
247
+ })
248
+ assert .ErrorContains (t , err , "PD011937" )
249
+ }
250
+
125
251
func TestPrivateTransactionsDeployAndExecute (t * testing.T ) {
126
252
// Coarse grained black box test of the core component manager
127
253
// no mocking although it does use a simple domain implementation that exists solely for testing
@@ -132,7 +258,7 @@ func TestPrivateTransactionsDeployAndExecute(t *testing.T) {
132
258
// The bootstrap code that is the entry point to the java side is not tested here, we bootstrap the component manager by hand
133
259
134
260
ctx := context .Background ()
135
- instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil )
261
+ instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil , false )
136
262
rpcClient := instance .client
137
263
138
264
// Check there are no transactions before we start
@@ -222,7 +348,7 @@ func TestPrivateTransactionsMintThenTransfer(t *testing.T) {
222
348
// Invoke 2 transactions on the same contract where the second transaction relies on the state created by the first
223
349
224
350
ctx := context .Background ()
225
- instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil )
351
+ instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil , false )
226
352
rpcClient := instance .client
227
353
228
354
// Check there are no transactions before we start
@@ -328,7 +454,7 @@ func TestPrivateTransactionRevertedAssembleFailed(t *testing.T) {
328
454
// Invoke a transaction that will fail to assemble
329
455
// in this case, we use the simple token domain and attempt to transfer from a wallet that has no tokens
330
456
ctx := context .Background ()
331
- instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil )
457
+ instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil , false )
332
458
rpcClient := instance .client
333
459
334
460
var dplyTxID uuid.UUID
@@ -438,13 +564,13 @@ func TestDeployOnOneNodeInvokeOnAnother(t *testing.T) {
438
564
439
565
domainRegistryAddress := deployDomainRegistry (t )
440
566
441
- instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , nil , nil , nil )
567
+ instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , nil , nil , nil , false )
442
568
client1 := instance1 .client
443
569
aliceIdentity := "wallets.org1.alice"
444
570
aliceAddress := instance1 .resolveEthereumAddress (aliceIdentity )
445
571
t .Logf ("Alice address: %s" , aliceAddress )
446
572
447
- instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , nil , nil , nil )
573
+ instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , nil , nil , nil , false )
448
574
client2 := instance2 .client
449
575
bobIdentity := "wallets.org2.bob"
450
576
bobAddress := instance2 .resolveEthereumAddress (bobIdentity )
@@ -553,13 +679,13 @@ func TestResolveIdentityFromRemoteNode(t *testing.T) {
553
679
aliceNodeConfig := newNodeConfiguration (t , "alice" )
554
680
bobNodeConfig := newNodeConfiguration (t , "bob" )
555
681
556
- instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig }, nil )
682
+ instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig }, nil , false )
557
683
client1 := instance1 .client
558
684
aliceIdentity := "wallets.org1.alice@" + instance1 .name
559
685
aliceAddress := instance1 .resolveEthereumAddress (aliceIdentity )
560
686
t .Logf ("Alice address: %s" , aliceAddress )
561
687
562
- instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig }, nil )
688
+ instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig }, nil , false )
563
689
client2 := instance2 .client
564
690
bobUnqualifiedIdentity := "wallets.org2.bob"
565
691
bobIdentity := bobUnqualifiedIdentity + "@" + instance2 .name
@@ -702,14 +828,14 @@ func TestNotaryDelegated(t *testing.T) {
702
828
703
829
domainRegistryAddress := deployDomainRegistry (t )
704
830
705
- instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig , notaryNodeConfig }, nil )
831
+ instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig , notaryNodeConfig }, nil , false )
706
832
client1 := instance1 .client
707
833
aliceIdentity := "wallets.org1.alice@" + instance1 .name
708
834
709
- instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig , notaryNodeConfig }, nil )
835
+ instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig , notaryNodeConfig }, nil , false )
710
836
bobIdentity := "wallets.org2.bob@" + instance2 .name
711
837
712
- instance3 := newInstanceForComponentTesting (t , domainRegistryAddress , notaryNodeConfig , []* nodeConfiguration {aliceNodeConfig , bobNodeConfig }, nil )
838
+ instance3 := newInstanceForComponentTesting (t , domainRegistryAddress , notaryNodeConfig , []* nodeConfiguration {aliceNodeConfig , bobNodeConfig }, nil , false )
713
839
client3 := instance3 .client
714
840
notaryIdentity := "wallets.org3.notary@" + instance3 .name
715
841
@@ -813,14 +939,14 @@ func TestNotaryDelegatedPrepare(t *testing.T) {
813
939
814
940
domainRegistryAddress := deployDomainRegistry (t )
815
941
816
- instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig , notaryNodeConfig }, nil )
942
+ instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig , notaryNodeConfig }, nil , false )
817
943
client1 := instance1 .client
818
944
aliceIdentity := "wallets.org1.alice@" + instance1 .name
819
945
820
- instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig , notaryNodeConfig }, nil )
946
+ instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig , notaryNodeConfig }, nil , false )
821
947
bobIdentity := "wallets.org2.bob@" + instance2 .name
822
948
823
- instance3 := newInstanceForComponentTesting (t , domainRegistryAddress , notaryNodeConfig , []* nodeConfiguration {aliceNodeConfig , bobNodeConfig }, nil )
949
+ instance3 := newInstanceForComponentTesting (t , domainRegistryAddress , notaryNodeConfig , []* nodeConfiguration {aliceNodeConfig , bobNodeConfig }, nil , false )
824
950
client3 := instance3 .client
825
951
notaryIdentity := "wallets.org3.notary@" + instance3 .name
826
952
@@ -944,7 +1070,7 @@ func TestSingleNodeSelfEndorseConcurrentSpends(t *testing.T) {
944
1070
// if there is no contention, each transfer should be able to spend a coin each
945
1071
946
1072
ctx := context .Background ()
947
- instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil )
1073
+ instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil , false )
948
1074
rpcClient := instance .client
949
1075
950
1076
var dplyTxID uuid.UUID
@@ -1070,7 +1196,7 @@ func TestSingleNodeSelfEndorseSeriesOfTransfers(t *testing.T) {
1070
1196
//where each transaction relies on the state created by the previous
1071
1197
1072
1198
ctx := context .Background ()
1073
- instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil )
1199
+ instance := newInstanceForComponentTesting (t , deployDomainRegistry (t ), nil , nil , nil , false )
1074
1200
rpcClient := instance .client
1075
1201
1076
1202
// Check there are no transactions before we start
@@ -1217,14 +1343,14 @@ func TestNotaryEndorseConcurrentSpends(t *testing.T) {
1217
1343
1218
1344
domainRegistryAddress := deployDomainRegistry (t )
1219
1345
1220
- instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig , notaryNodeConfig }, nil )
1346
+ instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig , notaryNodeConfig }, nil , false )
1221
1347
client1 := instance1 .client
1222
1348
aliceIdentity := "wallets.org1.alice@" + instance1 .name
1223
1349
1224
- instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig , notaryNodeConfig }, nil )
1350
+ instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig , notaryNodeConfig }, nil , false )
1225
1351
bobIdentity := "wallets.org2.bob@" + instance2 .name
1226
1352
1227
- instance3 := newInstanceForComponentTesting (t , domainRegistryAddress , notaryNodeConfig , []* nodeConfiguration {aliceNodeConfig , bobNodeConfig }, nil )
1353
+ instance3 := newInstanceForComponentTesting (t , domainRegistryAddress , notaryNodeConfig , []* nodeConfiguration {aliceNodeConfig , bobNodeConfig }, nil , false )
1228
1354
client3 := instance3 .client
1229
1355
notaryIdentity := "wallets.org3.notary@" + instance3 .name
1230
1356
@@ -1355,15 +1481,15 @@ func TestNotaryEndorseSeriesOfTransfers(t *testing.T) {
1355
1481
1356
1482
domainRegistryAddress := deployDomainRegistry (t )
1357
1483
1358
- instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig , notaryNodeConfig }, nil )
1484
+ instance1 := newInstanceForComponentTesting (t , domainRegistryAddress , aliceNodeConfig , []* nodeConfiguration {bobNodeConfig , notaryNodeConfig }, nil , false )
1359
1485
client1 := instance1 .client
1360
1486
aliceIdentity := "wallets.org1.alice@" + instance1 .name
1361
1487
1362
- instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig , notaryNodeConfig }, nil )
1488
+ instance2 := newInstanceForComponentTesting (t , domainRegistryAddress , bobNodeConfig , []* nodeConfiguration {aliceNodeConfig , notaryNodeConfig }, nil , false )
1363
1489
client2 := instance2 .client
1364
1490
bobIdentity := "wallets.org2.bob@" + instance2 .name
1365
1491
1366
- instance3 := newInstanceForComponentTesting (t , domainRegistryAddress , notaryNodeConfig , []* nodeConfiguration {aliceNodeConfig , bobNodeConfig }, nil )
1492
+ instance3 := newInstanceForComponentTesting (t , domainRegistryAddress , notaryNodeConfig , []* nodeConfiguration {aliceNodeConfig , bobNodeConfig }, nil , false )
1367
1493
client3 := instance3 .client
1368
1494
notaryIdentity := "wallets.org3.notary@" + instance3 .name
1369
1495
0 commit comments