Skip to content

Commit

Permalink
fix: correctly set handle owner when handle is upgraded to cip68
Browse files Browse the repository at this point in the history
add new chain-sync dataset with a problematic block
  • Loading branch information
mkazlauskas committed Sep 11, 2024
1 parent 7d78ad4 commit 3634303
Show file tree
Hide file tree
Showing 4 changed files with 7,212 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { BaseProjectionEvent } from '@cardano-sdk/projection';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { ChainSyncDataSet, chainSyncData } from '@cardano-sdk/util-dev';
import { HandleEntity } from '../../../src';
import { ProjectorContext, createProjectorContext, createStubProjectionSource } from '../util';
import { ProjectorContext, createProjectorContext, createStubProjectionSource, filterAssets } from '../util';
import { QueryRunner } from 'typeorm';
import { createMultiTxProjectionSource, entities, mapAndStore, projectTilFirst } from './util';
import { createMultiTxProjectionSource, entities, mapAndStore, project$, projectTilFirst } from './util';
import { firstValueFrom } from 'rxjs';
import { initializeDataSource } from '../../util';

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

it('upgrading handle to cip68 sets owner address to user nft (222) holder', async () => {
const eventsWithCip68Handle = filterAssets(chainSyncData(ChainSyncDataSet.Cip68HandleProblem), [
Cardano.AssetId('f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a000de14073696c766572666f78'),
Cardano.AssetId('f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a000643b073696c766572666f78')
]);
const evt = await firstValueFrom(project$(context, eventsWithCip68Handle.cardanoNode)());
const silverfoxHandle = evt.handles.find(({ handle }) => handle === 'silverfox');
expect(silverfoxHandle).toBeTruthy();
expect(silverfoxHandle?.latestOwnerAddress).toBe(
'addr1qx9t73ew53xtgt5tlruq8gr3grwca0urr0z9j2hre0gnlj0xe7yuukw0jrjaa2zvxnvga0zvycthvuf4l28yev95trdqq8q6rn'
);
});

describe('multiple transactions in 1 block', () => {
const maryAddress = Cardano.PaymentAddress(
'addr_test1qz690wvatwqgzt5u85hfzjxa8qqzthqwtp7xq8t3wh6ttc98hqtvlesvrpvln3srklcvhu2r9z22fdhaxvh2m2pg3nuq0n8gf2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
withTypeormTransaction
} from '../../../src';
import { Bootstrap, Mappers, ProjectionEvent, requestNext } from '@cardano-sdk/projection';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano, ChainSyncEventType, ObservableCardanoNode } from '@cardano-sdk/core';
import { ChainSyncDataSet, chainSyncData, logger, mockProviders } from '@cardano-sdk/util-dev';
import { Observable } from 'rxjs';
import { ProjectorContext, createProjectorTilFirst, createStubProjectionSource } from '../util';
Expand Down Expand Up @@ -113,14 +113,15 @@ export const mapAndStore =
evt$.pipe(applyMappers, storeData(buffer));

export const project$ =
({ buffer, tipTracker }: ProjectorContext) =>
({ buffer, tipTracker }: ProjectorContext, cardanoNode: ObservableCardanoNode = stubEvents.cardanoNode) =>
() =>
Bootstrap.fromCardanoNode({
blocksBufferLength: 10,
buffer,
cardanoNode: stubEvents.cardanoNode,
cardanoNode,
logger,
projectedTip$: tipTracker.tip$
}).pipe(mapAndStore({ buffer, tipTracker }), tipTracker.trackProjectedTip(), requestNext());

export const projectTilFirst = (context: ProjectorContext) => createProjectorTilFirst(project$(context));
export const projectTilFirst = (context: ProjectorContext, cardanoNode?: ObservableCardanoNode) =>
createProjectorTilFirst(project$(context, cardanoNode));
Loading

0 comments on commit 3634303

Please sign in to comment.