Skip to content

Commit 0e61490

Browse files
authored
Merge pull request #1468 from input-output-hk/fix/handle-cip68-upgrade
fix: correctly set handle owner when handle is upgraded to cip68
2 parents 9191c20 + 71204e0 commit 0e61490

File tree

5 files changed

+7214
-9
lines changed

5 files changed

+7214
-9
lines changed

packages/projection-typeorm/test/operators/storeHandles/ownership.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { BaseProjectionEvent } from '@cardano-sdk/projection';
22
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
3+
import { ChainSyncDataSet, chainSyncData } from '@cardano-sdk/util-dev';
34
import { HandleEntity } from '../../../src';
4-
import { ProjectorContext, createProjectorContext, createStubProjectionSource } from '../util';
5+
import { ProjectorContext, createProjectorContext, createStubProjectionSource, filterAssets } from '../util';
56
import { QueryRunner } from 'typeorm';
6-
import { createMultiTxProjectionSource, entities, mapAndStore, projectTilFirst } from './util';
7+
import { createMultiTxProjectionSource, entities, mapAndStore, project$, projectTilFirst } from './util';
78
import { firstValueFrom } from 'rxjs';
89
import { initializeDataSource } from '../../util';
910

@@ -156,6 +157,19 @@ describe('storeHandles', () => {
156157
expect(handleInDbAfterTransferRollback?.cardanoAddress).toEqual(originalOwnerAddress);
157158
});
158159

160+
it('upgrading handle to cip68 sets owner address to user nft (222) holder', async () => {
161+
const eventsWithCip68Handle = filterAssets(chainSyncData(ChainSyncDataSet.Cip68HandleProblem), [
162+
Cardano.AssetId('f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a000de14073696c766572666f78'),
163+
Cardano.AssetId('f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a000643b073696c766572666f78')
164+
]);
165+
const evt = await firstValueFrom(project$(context, eventsWithCip68Handle.cardanoNode)());
166+
const silverfoxHandle = evt.handles.find(({ handle }) => handle === 'silverfox');
167+
expect(silverfoxHandle).toBeTruthy();
168+
expect(silverfoxHandle?.latestOwnerAddress).toBe(
169+
'addr1qx9t73ew53xtgt5tlruq8gr3grwca0urr0z9j2hre0gnlj0xe7yuukw0jrjaa2zvxnvga0zvycthvuf4l28yev95trdqq8q6rn'
170+
);
171+
});
172+
159173
describe('multiple transactions in 1 block', () => {
160174
const maryAddress = Cardano.PaymentAddress(
161175
'addr_test1qz690wvatwqgzt5u85hfzjxa8qqzthqwtp7xq8t3wh6ttc98hqtvlesvrpvln3srklcvhu2r9z22fdhaxvh2m2pg3nuq0n8gf2'

packages/projection-typeorm/test/operators/storeHandles/util.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
withTypeormTransaction
2222
} from '../../../src';
2323
import { Bootstrap, Mappers, ProjectionEvent, requestNext } from '@cardano-sdk/projection';
24-
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
24+
import { Cardano, ChainSyncEventType, ObservableCardanoNode } from '@cardano-sdk/core';
2525
import { ChainSyncDataSet, chainSyncData, logger, mockProviders } from '@cardano-sdk/util-dev';
2626
import { Observable } from 'rxjs';
2727
import { ProjectorContext, createProjectorTilFirst, createStubProjectionSource } from '../util';
@@ -113,14 +113,15 @@ export const mapAndStore =
113113
evt$.pipe(applyMappers, storeData(buffer));
114114

115115
export const project$ =
116-
({ buffer, tipTracker }: ProjectorContext) =>
116+
({ buffer, tipTracker }: ProjectorContext, cardanoNode: ObservableCardanoNode = stubEvents.cardanoNode) =>
117117
() =>
118118
Bootstrap.fromCardanoNode({
119119
blocksBufferLength: 10,
120120
buffer,
121-
cardanoNode: stubEvents.cardanoNode,
121+
cardanoNode,
122122
logger,
123123
projectedTip$: tipTracker.tip$
124124
}).pipe(mapAndStore({ buffer, tipTracker }), tipTracker.trackProjectedTip(), requestNext());
125125

126-
export const projectTilFirst = (context: ProjectorContext) => createProjectorTilFirst(project$(context));
126+
export const projectTilFirst = (context: ProjectorContext, cardanoNode?: ObservableCardanoNode) =>
127+
createProjectorTilFirst(project$(context, cardanoNode));

packages/projection/src/operators/Mappers/withHandles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ export const withHandles =
160160
const handleMap = evt.block.body.reduce(
161161
(handles, { body: { outputs, mint } }) => ({
162162
...handles,
163-
...getOutputHandles(outputs, policyIds, evt.cip67, logger),
164-
...getBurnedHandles(mint, policyIds, evt.cip67, logger)
163+
...getBurnedHandles(mint, policyIds, evt.cip67, logger),
164+
...getOutputHandles(outputs, policyIds, evt.cip67, logger)
165165
}),
166166
{} as Record<string, HandleOwnership>
167167
);

0 commit comments

Comments
 (0)