Skip to content

Commit 02657eb

Browse files
authored
fix: export effects from receipt (#81)
They were not being exported at all 😢
1 parent 559b0a5 commit 02657eb

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

core/receipt/receipt.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,16 @@ func (r *receipt[O, X]) Export() iter.Seq2[block.Block, error] {
247247
iterators = append(iterators, inv.Export())
248248
}
249249

250+
for _, f := range r.Fx().Fork() {
251+
if inv, ok := f.Invocation(); ok {
252+
iterators = append(iterators, inv.Export())
253+
}
254+
}
255+
256+
if inv, ok := r.Fx().Join().Invocation(); ok {
257+
iterators = append(iterators, inv.Export())
258+
}
259+
250260
for _, prf := range r.Proofs() {
251261
if delegation, ok := prf.Delegation(); ok {
252262
iterators = append(iterators, delegation.Export())
@@ -458,12 +468,6 @@ func Issue[O, X ipld.Builder](issuer ucan.Signer, out result.Result[O, X], ran r
458468
return nil, err
459469
}
460470

461-
// copy proof blocks into store
462-
prooflinks, err := cfg.prf.WriteInto(bs)
463-
if err != nil {
464-
return nil, err
465-
}
466-
467471
var forks []ipld.Link
468472
for _, effect := range cfg.forks {
469473
if inv, ok := effect.Invocation(); ok {
@@ -485,6 +489,12 @@ func Issue[O, X ipld.Builder](issuer ucan.Signer, out result.Result[O, X], ran r
485489
Join: join,
486490
}
487491

492+
// copy proof blocks into store
493+
prooflinks, err := cfg.prf.WriteInto(bs)
494+
if err != nil {
495+
return nil, err
496+
}
497+
488498
metaModel := rdm.MetaModel{}
489499
// attempt to convert meta into IPLD format if present.
490500
if cfg.meta != nil {

core/receipt/receipt_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,34 @@ func TestExport(t *testing.T) {
286286
)
287287
require.NoError(t, err)
288288

289+
forkFx := fx.FromInvocation(
290+
helpers.Must(
291+
invocation.Invoke(
292+
fixtures.Alice,
293+
fixtures.Bob,
294+
ucan.NewCapability("test/fx/fork", fixtures.Alice.DID().String(), ucan.NoCaveats{}),
295+
),
296+
),
297+
)
298+
299+
joinFx := fx.FromInvocation(
300+
helpers.Must(
301+
invocation.Invoke(
302+
fixtures.Alice,
303+
fixtures.Bob,
304+
ucan.NewCapability("test/fx/join", fixtures.Alice.DID().String(), ucan.NoCaveats{}),
305+
),
306+
),
307+
)
308+
289309
ran := ran.FromInvocation(inv)
290310
ok := someOkType{SomeOkProperty: "some ok value"}
291311
rcpt, err := Issue(
292312
fixtures.Alice,
293313
result.Ok[someOkType, someErrorType](ok),
294314
ran,
315+
WithFork(forkFx, fx.FromLink(helpers.RandomCID())),
316+
WithJoin(joinFx),
295317
WithProofs(delegation.Proofs{
296318
delegation.FromDelegation(prf),
297319
// include an absent proof to prove things don't break - PUN INTENDED
@@ -309,7 +331,7 @@ func TestExport(t *testing.T) {
309331
require.NoError(t, bs.Put(b))
310332
blks = append(blks, b)
311333
}
312-
require.Len(t, blks, 3)
334+
require.Len(t, blks, 5)
313335
require.True(t, slices.ContainsFunc(blks, func(b ipld.Block) bool {
314336
return b.Link().String() == prf.Link().String()
315337
}))

0 commit comments

Comments
 (0)