Skip to content

Commit c62498b

Browse files
Merge pull request #575 from annamcallister/update-public-tx
Update public transactions
2 parents 889598a + 133aaa0 commit c62498b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3102
-1426
lines changed

core/go/componenttest/component_test.go

Lines changed: 149 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/google/uuid"
3030
"github.com/hyperledger/firefly-signer/pkg/abi"
31+
"github.com/kaleido-io/paladin/config/pkg/confutil"
3132
"github.com/kaleido-io/paladin/core/componenttest/domains"
3233
"github.com/kaleido-io/paladin/core/pkg/blockindexer"
3334
"github.com/kaleido-io/paladin/core/pkg/persistence"
@@ -46,11 +47,10 @@ import (
4647
)
4748

4849
func TestRunSimpleStorageEthTransaction(t *testing.T) {
49-
//TODO refactor this to be more black box by using JSONRPC interface to invoke the public contract
5050
ctx := context.Background()
5151
logrus.SetLevel(logrus.DebugLevel)
5252

53-
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil)
53+
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil, false)
5454
cm := instance.cm
5555
c := pldclient.Wrap(instance.client).ReceiptPollingInterval(250 * time.Millisecond)
5656

@@ -122,6 +122,132 @@ func TestRunSimpleStorageEthTransaction(t *testing.T) {
122122

123123
}
124124

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+
125251
func TestPrivateTransactionsDeployAndExecute(t *testing.T) {
126252
// Coarse grained black box test of the core component manager
127253
// no mocking although it does use a simple domain implementation that exists solely for testing
@@ -132,7 +258,7 @@ func TestPrivateTransactionsDeployAndExecute(t *testing.T) {
132258
// The bootstrap code that is the entry point to the java side is not tested here, we bootstrap the component manager by hand
133259

134260
ctx := context.Background()
135-
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil)
261+
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil, false)
136262
rpcClient := instance.client
137263

138264
// Check there are no transactions before we start
@@ -222,7 +348,7 @@ func TestPrivateTransactionsMintThenTransfer(t *testing.T) {
222348
// Invoke 2 transactions on the same contract where the second transaction relies on the state created by the first
223349

224350
ctx := context.Background()
225-
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil)
351+
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil, false)
226352
rpcClient := instance.client
227353

228354
// Check there are no transactions before we start
@@ -328,7 +454,7 @@ func TestPrivateTransactionRevertedAssembleFailed(t *testing.T) {
328454
// Invoke a transaction that will fail to assemble
329455
// in this case, we use the simple token domain and attempt to transfer from a wallet that has no tokens
330456
ctx := context.Background()
331-
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil)
457+
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil, false)
332458
rpcClient := instance.client
333459

334460
var dplyTxID uuid.UUID
@@ -438,13 +564,13 @@ func TestDeployOnOneNodeInvokeOnAnother(t *testing.T) {
438564

439565
domainRegistryAddress := deployDomainRegistry(t)
440566

441-
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, nil, nil, nil)
567+
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, nil, nil, nil, false)
442568
client1 := instance1.client
443569
aliceIdentity := "wallets.org1.alice"
444570
aliceAddress := instance1.resolveEthereumAddress(aliceIdentity)
445571
t.Logf("Alice address: %s", aliceAddress)
446572

447-
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, nil, nil, nil)
573+
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, nil, nil, nil, false)
448574
client2 := instance2.client
449575
bobIdentity := "wallets.org2.bob"
450576
bobAddress := instance2.resolveEthereumAddress(bobIdentity)
@@ -553,13 +679,13 @@ func TestResolveIdentityFromRemoteNode(t *testing.T) {
553679
aliceNodeConfig := newNodeConfiguration(t, "alice")
554680
bobNodeConfig := newNodeConfiguration(t, "bob")
555681

556-
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig}, nil)
682+
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig}, nil, false)
557683
client1 := instance1.client
558684
aliceIdentity := "wallets.org1.alice@" + instance1.name
559685
aliceAddress := instance1.resolveEthereumAddress(aliceIdentity)
560686
t.Logf("Alice address: %s", aliceAddress)
561687

562-
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig}, nil)
688+
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig}, nil, false)
563689
client2 := instance2.client
564690
bobUnqualifiedIdentity := "wallets.org2.bob"
565691
bobIdentity := bobUnqualifiedIdentity + "@" + instance2.name
@@ -702,14 +828,14 @@ func TestNotaryDelegated(t *testing.T) {
702828

703829
domainRegistryAddress := deployDomainRegistry(t)
704830

705-
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig, notaryNodeConfig}, nil)
831+
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig, notaryNodeConfig}, nil, false)
706832
client1 := instance1.client
707833
aliceIdentity := "wallets.org1.alice@" + instance1.name
708834

709-
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig, notaryNodeConfig}, nil)
835+
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig, notaryNodeConfig}, nil, false)
710836
bobIdentity := "wallets.org2.bob@" + instance2.name
711837

712-
instance3 := newInstanceForComponentTesting(t, domainRegistryAddress, notaryNodeConfig, []*nodeConfiguration{aliceNodeConfig, bobNodeConfig}, nil)
838+
instance3 := newInstanceForComponentTesting(t, domainRegistryAddress, notaryNodeConfig, []*nodeConfiguration{aliceNodeConfig, bobNodeConfig}, nil, false)
713839
client3 := instance3.client
714840
notaryIdentity := "wallets.org3.notary@" + instance3.name
715841

@@ -813,14 +939,14 @@ func TestNotaryDelegatedPrepare(t *testing.T) {
813939

814940
domainRegistryAddress := deployDomainRegistry(t)
815941

816-
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig, notaryNodeConfig}, nil)
942+
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig, notaryNodeConfig}, nil, false)
817943
client1 := instance1.client
818944
aliceIdentity := "wallets.org1.alice@" + instance1.name
819945

820-
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig, notaryNodeConfig}, nil)
946+
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig, notaryNodeConfig}, nil, false)
821947
bobIdentity := "wallets.org2.bob@" + instance2.name
822948

823-
instance3 := newInstanceForComponentTesting(t, domainRegistryAddress, notaryNodeConfig, []*nodeConfiguration{aliceNodeConfig, bobNodeConfig}, nil)
949+
instance3 := newInstanceForComponentTesting(t, domainRegistryAddress, notaryNodeConfig, []*nodeConfiguration{aliceNodeConfig, bobNodeConfig}, nil, false)
824950
client3 := instance3.client
825951
notaryIdentity := "wallets.org3.notary@" + instance3.name
826952

@@ -944,7 +1070,7 @@ func TestSingleNodeSelfEndorseConcurrentSpends(t *testing.T) {
9441070
// if there is no contention, each transfer should be able to spend a coin each
9451071

9461072
ctx := context.Background()
947-
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil)
1073+
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil, false)
9481074
rpcClient := instance.client
9491075

9501076
var dplyTxID uuid.UUID
@@ -1070,7 +1196,7 @@ func TestSingleNodeSelfEndorseSeriesOfTransfers(t *testing.T) {
10701196
//where each transaction relies on the state created by the previous
10711197

10721198
ctx := context.Background()
1073-
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil)
1199+
instance := newInstanceForComponentTesting(t, deployDomainRegistry(t), nil, nil, nil, false)
10741200
rpcClient := instance.client
10751201

10761202
// Check there are no transactions before we start
@@ -1217,14 +1343,14 @@ func TestNotaryEndorseConcurrentSpends(t *testing.T) {
12171343

12181344
domainRegistryAddress := deployDomainRegistry(t)
12191345

1220-
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig, notaryNodeConfig}, nil)
1346+
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig, notaryNodeConfig}, nil, false)
12211347
client1 := instance1.client
12221348
aliceIdentity := "wallets.org1.alice@" + instance1.name
12231349

1224-
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig, notaryNodeConfig}, nil)
1350+
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig, notaryNodeConfig}, nil, false)
12251351
bobIdentity := "wallets.org2.bob@" + instance2.name
12261352

1227-
instance3 := newInstanceForComponentTesting(t, domainRegistryAddress, notaryNodeConfig, []*nodeConfiguration{aliceNodeConfig, bobNodeConfig}, nil)
1353+
instance3 := newInstanceForComponentTesting(t, domainRegistryAddress, notaryNodeConfig, []*nodeConfiguration{aliceNodeConfig, bobNodeConfig}, nil, false)
12281354
client3 := instance3.client
12291355
notaryIdentity := "wallets.org3.notary@" + instance3.name
12301356

@@ -1355,15 +1481,15 @@ func TestNotaryEndorseSeriesOfTransfers(t *testing.T) {
13551481

13561482
domainRegistryAddress := deployDomainRegistry(t)
13571483

1358-
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig, notaryNodeConfig}, nil)
1484+
instance1 := newInstanceForComponentTesting(t, domainRegistryAddress, aliceNodeConfig, []*nodeConfiguration{bobNodeConfig, notaryNodeConfig}, nil, false)
13591485
client1 := instance1.client
13601486
aliceIdentity := "wallets.org1.alice@" + instance1.name
13611487

1362-
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig, notaryNodeConfig}, nil)
1488+
instance2 := newInstanceForComponentTesting(t, domainRegistryAddress, bobNodeConfig, []*nodeConfiguration{aliceNodeConfig, notaryNodeConfig}, nil, false)
13631489
client2 := instance2.client
13641490
bobIdentity := "wallets.org2.bob@" + instance2.name
13651491

1366-
instance3 := newInstanceForComponentTesting(t, domainRegistryAddress, notaryNodeConfig, []*nodeConfiguration{aliceNodeConfig, bobNodeConfig}, nil)
1492+
instance3 := newInstanceForComponentTesting(t, domainRegistryAddress, notaryNodeConfig, []*nodeConfiguration{aliceNodeConfig, bobNodeConfig}, nil, false)
13671493
client3 := instance3.client
13681494
notaryIdentity := "wallets.org3.notary@" + instance3.name
13691495

0 commit comments

Comments
 (0)