Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade logion deps #560

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"license": "Apache-2.0",
"dependencies": {
"@creativecommons/cc-assets": "^0.1.0",
"@logion/client": "^0.42.0",
"@logion/client": "^0.43.0-3",
"@logion/client-browser": "^0.3.4",
"@logion/crossmint": "^0.1.32",
"@logion/extension": "^0.7.8",
"@logion/extension": "^0.8.0-1",
"@logion/multiversx": "^0.1.13",
"@multiversx/sdk-extension-provider": "^2.0.7",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
Expand Down
2 changes: 2 additions & 0 deletions src/__mocks__/@logion/node-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export {
Hash,
Lgnt,
LgntFormatter,
ValidAccountId,
AnyAccountId,
} from "@logion/node-api";

export type {
Expand Down
27 changes: 14 additions & 13 deletions src/__mocks__/LogionClientMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TEST_WALLET_USER } from "../wallet-user/TestData";
export { toIsoString, fromIsoString } from "@logion/client/dist/DateTimeUtil.js";
import { api } from "./LogionMock";
import { VerifiedIssuerWithSelect } from "@logion/client/dist/Loc";
import { Hash } from "@logion/node-api";
import { Hash, ValidAccountId } from "@logion/node-api";
import { TokensRecord } from "@logion/client";

export const axiosMock = {
Expand All @@ -22,18 +22,18 @@ export class LogionClient {
return this;
}

withCurrentAddress() {
withCurrentAccount() {
return this;
}

tokens = new AccountTokens();

isLegalOfficer(address: string) {
return address === PATRICK.address || address === GUILLAUME.address || address === ALAIN.address;
isLegalOfficer(address: ValidAccountId) {
return address.equals(PATRICK.account) || address.equals(GUILLAUME.account) || address.equals(ALAIN.account);
}

isRegisteredLegalOfficer(address: string) {
return address === PATRICK.address || address === GUILLAUME.address || address === ALAIN.address;
isRegisteredLegalOfficer(address: ValidAccountId) {
return address.equals(PATRICK.account) || address.equals(GUILLAUME.account) || address.equals(ALAIN.account);
}

legalOfficers = threeLegalOfficers;
Expand Down Expand Up @@ -68,16 +68,17 @@ export class LogionClient {
},
findCollectionLocItemById: () => { isAuthenticatedTokenOwner: () => true },
};
currentAddress = TEST_WALLET_USER;

currentAccount = TEST_WALLET_USER;

logionApi = api.object();

getLegalOfficer(address: string) {
if(address === PATRICK.address) {
getLegalOfficer(address: ValidAccountId) {
if(address.equals(PATRICK.account)) {
return threeLegalOfficers[0];
} else if(address === GUILLAUME.address) {
} else if(address.equals(GUILLAUME.account)) {
return threeLegalOfficers[1];
} else if(address === ALAIN.address) {
} else if(address.equals(ALAIN.account)) {
return threeLegalOfficers[2];
} else {
throw new Error();
Expand All @@ -99,9 +100,9 @@ export class AccountTokens {
return this;
}

addresses = [ TEST_WALLET_USER ];
accounts = [ TEST_WALLET_USER ];

get(account: any) {
get(account: ValidAccountId) {
return ({
value: `some-token-value-for-${account.address}`,
expirationDateTime: DateTime.now().plus({hours: 1})
Expand Down
36 changes: 11 additions & 25 deletions src/__mocks__/LogionMock.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import { AccountType, ValidAccountId, LogionNodeApiClass, LegalOfficerCase, Hash, Lgnt } from "@logion/node-api";
import { ValidAccountId, LogionNodeApiClass, LegalOfficerCase, Hash, Lgnt, AccountType, AnyAccountId } from "@logion/node-api";
import { H256 } from "@logion/node-api/dist/types/interfaces";
import { It, Mock } from "moq.ts";
import type { Text, Compact, u128 } from '@polkadot/types-codec';
import type { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { TEST_WALLET_USER } from "src/wallet-user/TestData";
import { AccountId } from "@logion/node-api/dist/types/Types";

export const DEFAULT_LEGAL_OFFICER = mockValidPolkadotAccountId("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"); // Alice
export const ANOTHER_LEGAL_OFFICER = mockValidPolkadotAccountId("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"); // Bob
export const A_THIRD_LEGAL_OFFICER = mockValidPolkadotAccountId("5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y"); // Charlie

export function mockValidPolkadotAccountId(address: string): ValidAccountId {
return mockValidAccountId(address, "Polkadot");
}

export function mockValidAccountId(address: string, type: AccountType): ValidAccountId {
return {
address,
type,
toKey: () => `${type}:${address}`,
equals: (other: AccountId) => other.type === type && other.address === address,
} as ValidAccountId;
}
export const DEFAULT_LEGAL_OFFICER = ValidAccountId.polkadot("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"); // Alice
export const ANOTHER_LEGAL_OFFICER = ValidAccountId.polkadot("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"); // Bob
export const A_THIRD_LEGAL_OFFICER = ValidAccountId.polkadot("5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y"); // Charlie

export const api = new Mock<LogionNodeApiClass>();

api.setup(instance => instance.queries.getValidAccountId).returns((address: string, _type: string) => mockValidPolkadotAccountId(address));
api.setup(instance => instance.queries.getValidAccountId).returns((address: string, type: AccountType) => new AnyAccountId(address, type).toValidAccountId());

const localPeerId = new Mock<Text>();
localPeerId.setup(instance => instance.toString()).returns("Mock peer ID");
Expand All @@ -50,8 +36,8 @@ export function mockSubmittable(): Mock<SubmittableExtrinsic> {
export const CLOSED_IDENTITY_LOC_ID = "85833363768713528858922097642089825569";

export const CLOSED_IDENTITY_LOC: LegalOfficerCase = {
owner: DEFAULT_LEGAL_OFFICER.address,
requesterAddress: mockValidPolkadotAccountId("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"),
owner: DEFAULT_LEGAL_OFFICER,
requesterAccountId: ValidAccountId.polkadot("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"),
locType: 'Identity',
closed: true,
files: [
Expand All @@ -76,8 +62,8 @@ export const CLOSED_IDENTITY_LOC: LegalOfficerCase = {
export const OPEN_IDENTITY_LOC_ID = "195914524858768213081425411950368569411";

export const OPEN_IDENTITY_LOC: LegalOfficerCase = {
owner: DEFAULT_LEGAL_OFFICER.address,
requesterAddress: mockValidPolkadotAccountId("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"),
owner: DEFAULT_LEGAL_OFFICER,
requesterAccountId: ValidAccountId.polkadot("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"),
locType: 'Identity',
closed: false,
files: [],
Expand All @@ -93,8 +79,8 @@ export const OPEN_IDENTITY_LOC: LegalOfficerCase = {
export const CLOSED_COLLECTION_LOC_ID = "195914524858768213081425411950368569411";

export const CLOSED_COLLECTION_LOC: LegalOfficerCase = {
owner: DEFAULT_LEGAL_OFFICER.address,
requesterAddress: mockValidPolkadotAccountId("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"),
owner: DEFAULT_LEGAL_OFFICER,
requesterAccountId: ValidAccountId.polkadot("5Ew3MyB15VprZrjQVkpQFj8okmc9xLDSEdNhqMMS5cXsqxoW"),
locType: 'Collection',
closed: true,
files: [],
Expand Down
2 changes: 1 addition & 1 deletion src/__snapshots__/Login.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ exports[`Login renders 1`] = `
<div
className="address"
>
5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
vQx5kESPn8dWyX4KxMCKqUyCaWUwtui1isX6PVNcZh2Ghjitr
</div>
</div>
</div>
Expand Down
19 changes: 9 additions & 10 deletions src/certificate/Authenticate.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { render, screen } from '@testing-library/react';
import { clickByName, shallowRender } from '../tests';
import { UUID, Hash } from "@logion/node-api";
import { UUID, Hash, AnyAccountId, ValidAccountId } from "@logion/node-api";
import { HashString, ClientToken } from "@logion/client";
import { DEFAULT_LEGAL_OFFICER } from "../common/TestData";
import { setMetamaskEnabled } from '../__mocks__/LogionExtensionMock';
import { setClientMock } from 'src/logion-chain/__mocks__/LogionChainMock';
import { CollectionItem, UploadableItemFile, Token, ItemTokenWithRestrictedType } from '@logion/client';
import Authenticate, { Props } from "./Authenticate";
import { LogionClient } from 'src/__mocks__/LogionClientMock';
import { mockValidPolkadotAccountId } from 'src/__mocks__/LogionMock';

jest.mock('../logion-chain');

Expand All @@ -23,7 +22,7 @@ describe("Authenticate with Metamask", () => {
it("gets token for rightful owner of item", () => testOwnershipCheckSuccess(
metamaskAssetProps,
{ token: "some-token-value-for-0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84" },
"0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84"
new AnyAccountId("0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84", "Ethereum").toValidAccountId(),
));
it("does not get token if anyone else", () => testOwnershipCheckFailure(metamaskAssetProps));
})
Expand All @@ -38,7 +37,7 @@ describe("Authenticate with Crossmint", () => {
it("gets token for rightful owner of item", async () => testOwnershipCheckSuccess(
crossmintAssetProps,
{ token: "some-token-value-for-0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84" },
"0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84"
new AnyAccountId("0xa6db31d1aee06a3ad7e4e56de3775e80d2f5ea84", "Ethereum").toValidAccountId(),
));
it("does not get token if anyone else", async () => testOwnershipCheckFailure(crossmintAssetProps));
})
Expand All @@ -52,8 +51,8 @@ describe("Authenticate with Polkadot", () => {
it("renders button for restricted delivery of item asset", () => testRender(polkadotAssetProps))
it("gets token for rightful owner of item", async () => testOwnershipCheckSuccess(
polkadotAssetProps,
{ token: "some-token-value-for-5FniDvPw22DMW1TLee9N8zBjzwKXaKB2DcvZZCQU5tjmv1kb" },
"5FniDvPw22DMW1TLee9N8zBjzwKXaKB2DcvZZCQU5tjmv1kb"
{ token: "some-token-value-for-vQw1WXnZU4fCjzyXJqyrnojstSK4YFbtviVKRrBQeydk9je4F" },
ValidAccountId.polkadot("vQw1WXnZU4fCjzyXJqyrnojstSK4YFbtviVKRrBQeydk9je4F"),
));
it("does not get token if anyone else", async () => testOwnershipCheckFailure(crossmintAssetProps));
})
Expand Down Expand Up @@ -85,7 +84,7 @@ const item = {

const ownerToken: ItemTokenWithRestrictedType = {
type: "owner",
id: "5FniDvPw22DMW1TLee9N8zBjzwKXaKB2DcvZZCQU5tjmv1kb",
id: "vQw1WXnZU4fCjzyXJqyrnojstSK4YFbtviVKRrBQeydk9je4F",
issuance: 1n,
};

Expand Down Expand Up @@ -160,9 +159,9 @@ function expectTokenSet(value: string) {
expect(tokenForDownload?.value).toEqual(value);
}

function mockForCheckSuccess(address: string) {
function mockForCheckSuccess(address: ValidAccountId) {
const clientMock = new LogionClient();
clientMock.currentAddress = mockValidPolkadotAccountId(address);
clientMock.currentAccount = address;
const item = {
isAuthenticatedTokenOwner: () => true,
};
Expand All @@ -185,7 +184,7 @@ async function testOwnershipCheckFailure(props: Props) {
await expectOwnershipCheckFailure();
}

async function testOwnershipCheckSuccess(props: Props, params: { token: string }, address: string) {
async function testOwnershipCheckSuccess(props: Props, params: { token: string }, address: ValidAccountId) {
mockForCheckSuccess(address);
await renderAndClaim(props);
if (props.walletType === 'POLKADOT') {
Expand Down
2 changes: 1 addition & 1 deletion src/certificate/Authenticate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function Authenticate(props: Props) {
const newItem = await client.public.findCollectionLocItemById({ locId, itemId: item.id });
const isOwner = newItem && await newItem.isAuthenticatedTokenOwner();
if (isOwner) {
setTokenForDownload(client.tokens.get(client.currentAddress));
setTokenForDownload(client.tokens.get(client.currentAccount));
setStatus('OWNER_OK');
} else {
setStatus('OWNER_KO');
Expand Down
7 changes: 4 additions & 3 deletions src/certificate/Certificate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Certificate from './Certificate';
import { setClientMock } from 'src/logion-chain/__mocks__/LogionChainMock';
import { PATRICK } from 'src/common/TestData';
import { URLSearchParams } from 'url';
import { TEST_WALLET_USER } from 'src/wallet-user/TestData';

jest.mock("react-router");
jest.mock("react-router-dom");
Expand Down Expand Up @@ -95,7 +96,7 @@ describe("Certificate", () => {

await waitFor(() => expect(screen.getByText("Legal Officer Case")).toBeVisible());
expect(screen.getByText("Tokens record")).toBeVisible();
expect(screen.getByText(mockTRCellContent(tokensRecord.issuer))).toBeVisible();
expect(screen.getByText(mockTRCellContent(tokensRecord.issuer.address))).toBeVisible();
expect(screen.getByText(mockTRCellContent(tokensRecord.description.validValue()))).toBeVisible();
expect(screen.getByText(mockTRCellContent(tokensRecord.files[0].contentType.validValue()))).toBeVisible();
expect(screen.getByText(tokensRecord.files[0].name.validValue())).toBeVisible();
Expand Down Expand Up @@ -127,7 +128,7 @@ function mockPublicLoc(locId: UUID): PublicLoc {
return {
data: {
id: locId,
ownerAddress: PATRICK.address,
ownerAccountId: PATRICK.account,
files: [],
metadata: [],
links: [],
Expand Down Expand Up @@ -205,7 +206,7 @@ function mockTokensRecord(): ClientTokensRecord {
id: Hash.of("record-id"),
description: HashString.fromValue("Record Description"),
addedOn: "2022-08-23T07:27:46.128Z",
issuer: "record-issuer",
issuer: TEST_WALLET_USER,
files: [ {
name: HashString.fromValue("record-file-name.txt"),
hash: Hash.of("record-file-content"),
Expand Down
14 changes: 7 additions & 7 deletions src/certificate/Certificate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function Certificate() {

useEffect(() => {
if (client !== null && legalOfficer === null && loc) {
setLegalOfficer(client.legalOfficers.find(legalOfficer => legalOfficer.address === loc.data.ownerAddress) || null);
setLegalOfficer(client.legalOfficers.find(legalOfficer => legalOfficer.account.equals(loc.data.ownerAccountId)) || null);
}
}, [ client, legalOfficer, setLegalOfficer, loc ]);

Expand Down Expand Up @@ -188,7 +188,7 @@ export default function Certificate() {
return (
<div className="Certificate">
<CertificateCell md={ 4 } label="LOC ID">{ locId.toDecimalString() }</CertificateCell>
<CertificateCell md={ 4 } label="UNKNOWN OFFICER">{ loc.data.ownerAddress }</CertificateCell>
<CertificateCell md={ 4 } label="UNKNOWN OFFICER">{ loc.data.ownerAccountId.address }</CertificateCell>
</div>
)
}
Expand Down Expand Up @@ -351,9 +351,9 @@ export default function Certificate() {
<CertificateDateTimeCell md={ 3 } label="Closing Date" dateTime={ loc.data.closedOn } />
</Row>
<Row className="preamble-footer">
{ loc.data.requesterAddress &&
{ loc.data.requesterAccountId &&
<CertificateCell md={ 6 } label="Requester">
{ loc.data.requesterAddress.address }
{ loc.data.requesterAccountId.address }
</CertificateCell>
}
{ loc.data.requesterLocId &&
Expand Down Expand Up @@ -386,7 +386,7 @@ export default function Certificate() {
{ collectionItem !== null &&
<CollectionItemCellRow
locId={ locId }
owner={ legalOfficer.address }
owner={ legalOfficer.account }
item={ collectionItem! }
checkResult={ checkResult }
isVoid={ loc.data.voidInfo !== undefined }
Expand All @@ -396,7 +396,7 @@ export default function Certificate() {
{ tokensRecords !== null &&
<TokensRecords
locId={ locId }
owner={ legalOfficer.address }
owner={ legalOfficer.account }
collectionItem={ collectionItem! }
tokenForDownload={ tokenForDownload }
tokensRecords={ tokensRecords }
Expand Down Expand Up @@ -498,7 +498,7 @@ function FileCellRow(props: { loc: LocData, files: MergedFile[], checkResult: Ch
name: validValueOrHex(file.nature),
type: "Collection",
}}
owner={ props.loc.ownerAddress }
owner={ props.loc.ownerAccountId }
tokenForDownload={ props.tokenForDownload }
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/certificate/ClaimAssetButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const TOKEN_FOR_DOWNLOAD: Token = {

const assetProps = {
locId,
owner: DEFAULT_LEGAL_OFFICER.address,
owner: DEFAULT_LEGAL_OFFICER,
item,
file: claimedAsset,
};
Expand All @@ -76,7 +76,7 @@ const claimedCollectionFile: ClaimedFile = {

const collectionFileProps = {
locId,
owner: DEFAULT_LEGAL_OFFICER.address,
owner: DEFAULT_LEGAL_OFFICER,
item,
file: claimedCollectionFile,
};
Expand Down
4 changes: 2 additions & 2 deletions src/certificate/ClaimAssetButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Token, CollectionItem, TokensRecord, TypedFile } from "@logion/client";
import { UUID, Hash } from "@logion/node-api";
import { UUID, Hash, ValidAccountId } from "@logion/node-api";
import { AxiosInstance } from "axios";
import { useState, useEffect } from "react";
import ViewFileButton from "../common/ViewFileButton";
Expand All @@ -24,7 +24,7 @@ export interface ClaimedFile {

export interface Props {
locId: UUID,
owner: string,
owner: ValidAccountId,
item: CollectionItem,
record?: TokensRecord,
file: ClaimedFile,
Expand Down
4 changes: 2 additions & 2 deletions src/certificate/CollectionItemCellRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CheckHashResult, CollectionItem, Token } from "@logion/client";
import { UUID } from "@logion/node-api";
import { UUID, ValidAccountId } from "@logion/node-api";

import CertificateCell from "./CertificateCell";
import { Row } from "../common/Grid";
Expand All @@ -13,7 +13,7 @@ import { CertificateItemDetails } from "src/components/certificateitemdetails/Ce

export interface Props {
locId: UUID,
owner: string,
owner: ValidAccountId,
item: CollectionItem;
checkResult: CheckHashResult | undefined;
isVoid: boolean;
Expand Down
Loading
Loading