diff --git a/docs/pages/misc-pages/upgrade-guide.md b/docs/pages/misc-pages/upgrade-guide.md index 77c8a000c..bdb9206e0 100644 --- a/docs/pages/misc-pages/upgrade-guide.md +++ b/docs/pages/misc-pages/upgrade-guide.md @@ -16,6 +16,20 @@ converting the type: - To refer to `CredentialRegistrationId` as a type use `CredentialRegistrationId.Type`. - Constructing `new CredentialRegistrationId("")` is now `CredentialRegistrationId.fromHexString("")`. +The API now uses dedicated types instead of language primitives: +- Use `AccountAddress` instead of a string with base58 encoding. Use `AccountAddress.fromBase58('')` to construct it. +- Use `BlockHash` instead of a string with hex encoding. Use `BlockHash.fromHexString('')` to construct it. +- Use `TranactionHash` instead of a string with hex encoding. Use `TransactionHash.fromHexString('')` to construct it. +- Use `Energy` instead of a bigint. Use `Energy.create()` to construct it. +- Use `ReceiveName` instead of a string. Use `ReceiveName.fromString('.')` to construct it. +- Use `InitName` instead of a string. Use `Init.fromString('init_')` to construct it. +- Use `ContractName` instead of a string. Use `ContractName.fromString('')` to construct it. +- Use `EntrypointName` instead of a string. Use `EntrypointName.fromString('')` to construct it. +- Use `Parameter` instead of a string with hex encoding. Use `Parameter.fromHexString('')`. +- Use `SequenceNumber` (formerly called nonce) instead of a bigint. Use `SequenceNumber.create()` to construct it. +- Use `Timestamp` instead of a bigint. Can be constructed using `Timestamp.fromMillis()`. +- Use `Duration` instead of a bigint. Can be constructed using `Duration.fromMillis()`. + ### Web The `@concordium/web-sdk` now requires bundlers to respect `exports` field of diff --git a/examples/client/invokeContract.ts b/examples/client/invokeContract.ts index bfec355ed..dfd67d050 100644 --- a/examples/client/invokeContract.ts +++ b/examples/client/invokeContract.ts @@ -8,6 +8,8 @@ import { ContractTraceEvent, Energy, Parameter, + ReceiveName, + ReturnValue, createConcordiumClient, } from '@concordium/node-sdk'; import { credentials } from '@grpc/grpc-js'; @@ -110,7 +112,7 @@ const client = createConcordiumClient( const contract = ContractAddress.create(cli.flags.contract); const context: ContractContext = { // Required - method: cli.flags.receive, + method: ReceiveName.fromString(cli.flags.receive), contract, // Optional invoker, @@ -132,9 +134,12 @@ const client = createConcordiumClient( } else if (result.tag === 'success') { console.log('Invoke was succesful'); - const returnValue: string | undefined = result.returnValue; // If the invoked method has return value + const returnValue = result.returnValue; // If the invoked method has return value if (returnValue) { - console.log('The return value of the invoked method:', returnValue); + console.log( + 'The return value of the invoked method:', + ReturnValue.toHexString(returnValue) + ); } const events: ContractTraceEvent[] = result.events; diff --git a/examples/composed-examples/findAccountCreationBlock.ts b/examples/composed-examples/findAccountCreationBlock.ts index 88df2dc5a..b9995831e 100644 --- a/examples/composed-examples/findAccountCreationBlock.ts +++ b/examples/composed-examples/findAccountCreationBlock.ts @@ -84,7 +84,7 @@ const client = createConcordiumClient( for await (const summary of summaries) { if ( summary.type === 'accountCreation' && - summary.address === account.address + AccountAddress.equals(summary.address, account) ) { console.log( 'Hash of transaction that created the account:', diff --git a/examples/composed-examples/initAndUpdateContract.ts b/examples/composed-examples/initAndUpdateContract.ts index 8fdfa8d9a..40edcb27e 100644 --- a/examples/composed-examples/initAndUpdateContract.ts +++ b/examples/composed-examples/initAndUpdateContract.ts @@ -18,6 +18,11 @@ import { parseWallet, buildAccountSigner, affectedContracts, + ContractName, + ReceiveName, + Energy, + EntrypointName, + ReturnValue, } from '@concordium/node-sdk'; import { credentials } from '@grpc/grpc-js'; import { readFileSync } from 'node:fs'; @@ -78,9 +83,9 @@ const client = createConcordiumClient( const moduleRef = new ModuleReference( '44434352ddba724930d6b1b09cd58bd1fba6ad9714cf519566d5fe72d80da0d1' ); - const maxCost = 30000n; - const contractName = 'weather'; - const receiveName = 'weather.set'; + const maxCost = Energy.create(30000); + const contractName = ContractName.fromStringUnchecked('weather'); + const receiveName = ReceiveName.fromStringUnchecked('weather.set'); const schema = await client.getEmbeddedSchema(moduleRef); // --- Initialize Contract --- // @@ -148,7 +153,7 @@ const client = createConcordiumClient( const updateParams = serializeUpdateContractParameters( contractName, - 'set', + EntrypointName.fromString('set'), rainyWeather, schema ); @@ -191,21 +196,18 @@ const client = createConcordiumClient( const contextPostInit: ContractContext = { contract: unwrap(contractAddress), invoker: sender, - method: 'weather.get', + method: ReceiveName.fromString('weather.get'), }; const invokedPostInit = await client.invokeContract(contextPostInit); if (invokedPostInit.tag === 'success') { - const rawReturnValue = Buffer.from( - unwrap(invokedPostInit.returnValue), - 'hex' - ); + const rawReturnValue = unwrap(invokedPostInit.returnValue); const returnValue = deserializeReceiveReturnValue( - rawReturnValue, + ReturnValue.toBuffer(rawReturnValue), schema, - 'weather', - 'get' + contractName, + EntrypointName.fromString('get') ); console.log('\nThe weather is now:'); console.dir(returnValue, { depth: null, colors: true }); diff --git a/examples/composed-examples/listNumberAccountTransactions.ts b/examples/composed-examples/listNumberAccountTransactions.ts index 545dfed2e..4d3bf4bc1 100644 --- a/examples/composed-examples/listNumberAccountTransactions.ts +++ b/examples/composed-examples/listNumberAccountTransactions.ts @@ -89,7 +89,7 @@ const client = createConcordiumClient( // For each transaction in the block: trxLoop: for await (const trx of trxStream) { if (isTransferLikeSummary(trx)) { - const trxAcc = AccountAddress.fromBase58(trx.sender); + const trxAcc = trx.sender; // Loop over account dictionary entries to check if account // is already in dictionary: @@ -102,7 +102,7 @@ const client = createConcordiumClient( } // If account is not in dictionary, then add it: - dict[trx.sender] = 1; + dict[AccountAddress.toBase58(trx.sender)] = 1; } } } diff --git a/packages/common/src/schema.ts b/packages/common/src/schema.ts index bff618610..775fe4ee3 100644 --- a/packages/common/src/schema.ts +++ b/packages/common/src/schema.ts @@ -1,6 +1,9 @@ import * as wasm from '@concordium/rust-bindings'; import { Buffer } from 'buffer/index.js'; import JSONbig from 'json-bigint'; +import * as ContractName from './types/ContractName.js'; +import * as EntrypointName from './types/EntrypointName.js'; +import * as Parameter from './types/Parameter.js'; import { SchemaVersion, SmartContractTypeValues } from './types.js'; /** @@ -11,12 +14,12 @@ import { SchemaVersion, SmartContractTypeValues } from './types.js'; */ export function getInitContractParameterSchema( moduleSchema: ArrayBuffer, - contractName: string, + contractName: ContractName.Type, schemaVersion?: SchemaVersion -): Buffer { +): Uint8Array { const parameterSchema = wasm.getInitContractParameterSchema( Buffer.from(moduleSchema).toString('hex'), - contractName, + ContractName.toString(contractName), schemaVersion ); return Buffer.from(parameterSchema, 'hex'); @@ -31,14 +34,14 @@ export function getInitContractParameterSchema( */ export function getUpdateContractParameterSchema( moduleSchema: ArrayBuffer, - contractName: string, - receiveFunctionName: string, + contractName: ContractName.Type, + receiveFunctionName: EntrypointName.Type, schemaVersion?: SchemaVersion -): Buffer { +): Uint8Array { const parameterSchema = wasm.getReceiveContractParameterSchema( Buffer.from(moduleSchema).toString('hex'), - contractName, - receiveFunctionName, + ContractName.toString(contractName), + EntrypointName.toString(receiveFunctionName), schemaVersion ); return Buffer.from(parameterSchema, 'hex'); @@ -63,21 +66,21 @@ export function displayTypeSchemaTemplate(rawSchema: ArrayBuffer): string { * @returns serialized buffer of init contract parameters */ export function serializeInitContractParameters( - contractName: string, + contractName: ContractName.Type, // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types parameters: any, rawSchema: ArrayBuffer, schemaVersion?: SchemaVersion, verboseErrorMessage = false -): Buffer { +): Parameter.Type { const serializedParameters = wasm.serializeInitContractParameters( JSONbig.stringify(parameters), Buffer.from(rawSchema).toString('hex'), - contractName, + ContractName.toString(contractName), schemaVersion, verboseErrorMessage ); - return Buffer.from(serializedParameters, 'hex'); + return Parameter.fromBuffer(Buffer.from(serializedParameters, 'hex')); } /** @@ -90,23 +93,23 @@ export function serializeInitContractParameters( * @returns serialized buffer of update contract parameters */ export function serializeUpdateContractParameters( - contractName: string, - receiveFunctionName: string, + contractName: ContractName.Type, + receiveFunctionName: EntrypointName.Type, // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types parameters: any, rawSchema: ArrayBuffer, schemaVersion?: SchemaVersion, verboseErrorMessage = false -): Buffer { +): Parameter.Type { const serializedParameters = wasm.serializeReceiveContractParameters( JSONbig.stringify(parameters), Buffer.from(rawSchema).toString('hex'), - contractName, - receiveFunctionName, + ContractName.toString(contractName), + EntrypointName.toString(receiveFunctionName), schemaVersion, verboseErrorMessage ); - return Buffer.from(serializedParameters, 'hex'); + return Parameter.fromBuffer(Buffer.from(serializedParameters, 'hex')); } /** @@ -121,13 +124,13 @@ export function serializeTypeValue( value: any, rawSchema: ArrayBuffer, verboseErrorMessage = false -): Buffer { +): Parameter.Type { const serializedValue = wasm.serializeTypeValue( JSONbig.stringify(value), Buffer.from(rawSchema).toString('hex'), verboseErrorMessage ); - return Buffer.from(serializedValue, 'hex'); + return Parameter.fromBuffer(Buffer.from(serializedValue, 'hex')); } /** @@ -135,14 +138,14 @@ export function serializeTypeValue( * The return type is any, and the actual type should be determined by using the schema. */ export function deserializeContractState( - contractName: string, + contractName: ContractName.Type, schema: ArrayBuffer, state: ArrayBuffer, verboseErrorMessage = false // eslint-disable-next-line @typescript-eslint/no-explicit-any ): any { const serializedState = wasm.deserializeState( - contractName, + ContractName.toString(contractName), Buffer.from(state).toString('hex'), Buffer.from(schema).toString('hex'), verboseErrorMessage @@ -171,8 +174,8 @@ export function deserializeContractState( export function deserializeReceiveReturnValue( returnValueBytes: ArrayBuffer, moduleSchema: ArrayBuffer, - contractName: string, - functionName: string, + contractName: ContractName.Type, + functionName: EntrypointName.Type, schemaVersion?: number, verboseErrorMessage = false // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -180,8 +183,8 @@ export function deserializeReceiveReturnValue( const deserializedReturnValue = wasm.deserializeReceiveReturnValue( Buffer.from(returnValueBytes).toString('hex'), Buffer.from(moduleSchema).toString('hex'), - contractName, - functionName, + ContractName.toString(contractName), + EntrypointName.toString(functionName), schemaVersion, verboseErrorMessage ); @@ -209,16 +212,16 @@ export function deserializeReceiveReturnValue( export function deserializeReceiveError( errorBytes: ArrayBuffer, moduleSchema: ArrayBuffer, - contractName: string, - functionName: string, + contractName: ContractName.Type, + functionName: EntrypointName.Type, verboseErrorMessage = false // eslint-disable-next-line @typescript-eslint/no-explicit-any ): any { const deserializedError = wasm.deserializeReceiveError( Buffer.from(errorBytes).toString('hex'), Buffer.from(moduleSchema).toString('hex'), - contractName, - functionName, + ContractName.toString(contractName), + EntrypointName.toString(functionName), verboseErrorMessage ); try { @@ -244,14 +247,14 @@ export function deserializeReceiveError( export function deserializeInitError( errorBytes: ArrayBuffer, moduleSchema: ArrayBuffer, - contractName: string, + contractName: ContractName.Type, verboseErrorMessage = false // eslint-disable-next-line @typescript-eslint/no-explicit-any ): any { const deserializedError = wasm.deserializeInitError( Buffer.from(errorBytes).toString('hex'), Buffer.from(moduleSchema).toString('hex'), - contractName, + ContractName.toString(contractName), verboseErrorMessage ); try { diff --git a/packages/common/src/types/Parameter.ts b/packages/common/src/types/Parameter.ts index fe8731ec6..58e166cdd 100644 --- a/packages/common/src/types/Parameter.ts +++ b/packages/common/src/types/Parameter.ts @@ -87,7 +87,7 @@ export function fromSchemaType( value: unknown ): Parameter { const schemaBytes = serializeSchemaType(schemaType); - return fromBuffer(serializeTypeValue(value, schemaBytes)); + return serializeTypeValue(value, schemaBytes); } /** @@ -101,7 +101,7 @@ export function fromBase64SchemaType( value: unknown ): Parameter { const schemaBytes = Buffer.from(schemaBase64, 'base64'); - return fromBuffer(serializeTypeValue(value, schemaBytes)); + return serializeTypeValue(value, schemaBytes); } /** diff --git a/packages/common/test/schema.test.ts b/packages/common/test/schema.test.ts index be7b1dbfd..191e058bc 100644 --- a/packages/common/test/schema.test.ts +++ b/packages/common/test/schema.test.ts @@ -21,6 +21,7 @@ import { AUCTION_WITH_ERRORS_VIEW_RETURN_VALUE_SCHEMA, TEST_CONTRACT_U64, } from './resources/schema.js'; +import { ContractName, EntrypointName, Parameter } from '../src/index.js'; const U64_MAX = 18446744073709551615n; @@ -28,8 +29,8 @@ test('U64_MAX can be deserialized', () => { const returnVal = deserializeReceiveReturnValue( Buffer.from('ffffffffffffffff', 'hex'), Buffer.from(TEST_CONTRACT_U64, 'base64'), - 'test', - 'receive' + ContractName.fromStringUnchecked('test'), + EntrypointName.fromStringUnchecked('receive') ); expect(returnVal).toEqual(U64_MAX); @@ -40,8 +41,8 @@ test('schema template display', () => { fs.readFileSync('./test/resources/cis2-nft-schema.bin') ); const schemaVersion = 1; - const contractName = 'CIS2-NFT'; - const functionName = 'transfer'; + const contractName = ContractName.fromStringUnchecked('CIS2-NFT'); + const functionName = EntrypointName.fromStringUnchecked('transfer'); const template = displayTypeSchemaTemplate( getUpdateContractParameterSchema( fullSchema, @@ -57,7 +58,7 @@ test('schema template display', () => { test('test that deserializeContractState works', () => { const state = deserializeContractState( - 'PiggyBank', + ContractName.fromStringUnchecked('PiggyBank'), Buffer.from(V0_PIGGYBANK_SCHEMA, 'base64'), Buffer.from('00', 'hex') ); @@ -69,8 +70,8 @@ test('Receive return value can be deserialized', () => { const returnValue = deserializeReceiveReturnValue( Buffer.from('80f18c27', 'hex'), Buffer.from(CIS2_WCCD_STATE_SCHEMA, 'base64'), - 'CIS2-wCCD-State', - 'getBalance' + ContractName.fromStringUnchecked('CIS2-wCCD-State'), + EntrypointName.fromStringUnchecked('getBalance') ); expect(returnValue).toEqual('82000000'); @@ -109,8 +110,8 @@ test('Return value can be deserialized - auction', () => { Buffer.from( fs.readFileSync('./test/resources/auction-with-errors-schema.bin') ), - 'auction', - 'view' + ContractName.fromStringUnchecked('auction'), + EntrypointName.fromStringUnchecked('view') ); expectAuctionReturnValue(returnValue); @@ -132,8 +133,8 @@ test('Receive error can be deserialized', () => { const error = deserializeReceiveError( Buffer.from('ffff', 'hex'), Buffer.from(TEST_CONTRACT_SCHEMA, 'base64'), - 'TestContract', - 'receive_function' + ContractName.fromStringUnchecked('TestContract'), + EntrypointName.fromStringUnchecked('receive_function') ); expect(error).toEqual(-1n); @@ -154,7 +155,7 @@ test('Init error can be deserialized', () => { const error = deserializeInitError( Buffer.from('0100', 'hex'), Buffer.from(TEST_CONTRACT_SCHEMA, 'base64'), - 'TestContract' + ContractName.fromStringUnchecked('TestContract') ); expect(error).toEqual(1n); @@ -173,8 +174,8 @@ test('Init error can be deserialized using deserializeTypeValue', () => { test('serialize UpdateContractParameters using CIS2 contract', () => { const parameter = serializeUpdateContractParameters( - 'CIS2-NFT', - 'transfer', + ContractName.fromStringUnchecked('CIS2-NFT'), + EntrypointName.fromStringUnchecked('transfer'), [ { token_id: [], @@ -196,7 +197,7 @@ test('serialize UpdateContractParameters using CIS2 contract', () => { 1 ); - expect(parameter.toString('hex')).toBe( + expect(Parameter.toHexString(parameter)).toBe( '010000c80000c320b41f1997accd5d21c6bf4992370948ed711435e0e2c9302def62afd1295f004651a37c65c8461540decd511e7440d1ff6d4191b7e2133b7239b2485be1a4860000' ); }); @@ -204,8 +205,8 @@ test('serialize UpdateContractParameters using CIS2 contract', () => { test('serialize UpdateContractParameters using CIS2 contract and incorrect name', () => { const parameter = function () { serializeUpdateContractParameters( - 'CIS2-NFT', - 'non-existent', + ContractName.fromStringUnchecked('CIS2-NFT'), + EntrypointName.fromStringUnchecked('non-existent'), [ { token_id: [], @@ -251,8 +252,8 @@ test('serialize type value and serializeUpdateContractParameters give same resul fs.readFileSync('./test/resources/cis2-nft-schema.bin') ); const schemaVersion = 1; - const contractName = 'CIS2-NFT'; - const functionName = 'transfer'; + const contractName = ContractName.fromStringUnchecked('CIS2-NFT'); + const functionName = EntrypointName.fromStringUnchecked('transfer'); const serializedParameter = serializeUpdateContractParameters( contractName, @@ -272,8 +273,8 @@ test('serialize type value and serializeUpdateContractParameters give same resul ) ); - expect(serializedParameter.toString('hex')).toEqual( - serializedType.toString('hex') + expect(Parameter.toHexString(serializedParameter)).toEqual( + Parameter.toHexString(serializedType) ); }); @@ -285,18 +286,18 @@ test('serializeTypeValue throws an error if unable to serialize', () => { test('Parameter serialization works for U64_MAX', () => { const updateParam = serializeUpdateContractParameters( - 'test', - 'receive', + ContractName.fromStringUnchecked('test'), + EntrypointName.fromStringUnchecked('receive'), U64_MAX, Buffer.from(TEST_CONTRACT_U64, 'base64') ); const initParam = serializeInitContractParameters( - 'test', + ContractName.fromStringUnchecked('test'), U64_MAX, Buffer.from(TEST_CONTRACT_U64, 'base64') ); - expect(updateParam.toString('hex')).toEqual('ffffffffffffffff'); - expect(initParam.toString('hex')).toEqual('ffffffffffffffff'); + expect(Parameter.toHexString(updateParam)).toEqual('ffffffffffffffff'); + expect(Parameter.toHexString(initParam)).toEqual('ffffffffffffffff'); }); test('Parameter serialization errors on (U64_MAX + 1)', () => { @@ -304,14 +305,14 @@ test('Parameter serialization errors on (U64_MAX + 1)', () => { 'Unable to serialize parameters, due to: Unsigned integer required'; const updateParam = () => serializeUpdateContractParameters( - 'test', - 'receive', + ContractName.fromStringUnchecked('test'), + EntrypointName.fromStringUnchecked('receive'), U64_MAX + 1n, Buffer.from(TEST_CONTRACT_U64, 'base64') ); const initParam = () => serializeInitContractParameters( - 'test', + ContractName.fromStringUnchecked('test'), U64_MAX + 1n, Buffer.from(TEST_CONTRACT_U64, 'base64') ); diff --git a/packages/nodejs/test/CIS2Contract.test.ts b/packages/nodejs/test/CIS2Contract.test.ts index c20d2834f..33e91db43 100644 --- a/packages/nodejs/test/CIS2Contract.test.ts +++ b/packages/nodejs/test/CIS2Contract.test.ts @@ -281,7 +281,9 @@ describe('createTransfer', () => { parameter.json, Buffer.from(schema.value, 'base64') ); - expect(schemaSerialized.toString('hex')).toEqual(expectedParameterHex); + expect(Parameter.toHexString(schemaSerialized)).toEqual( + expectedParameterHex + ); }); }); diff --git a/packages/nodejs/test/CIS4Contract.test.ts b/packages/nodejs/test/CIS4Contract.test.ts index 495bf35bd..76aa2dec9 100644 --- a/packages/nodejs/test/CIS4Contract.test.ts +++ b/packages/nodejs/test/CIS4Contract.test.ts @@ -4,6 +4,7 @@ import { Timestamp, Energy, BlockHash, + Parameter, } from '@concordium/common-sdk'; import { serializeTypeValue } from '@concordium/common-sdk/schema'; import { CIS4, CIS4Contract, Web3IdSigner } from '@concordium/common-sdk/cis4'; @@ -171,7 +172,7 @@ describe('registerCredential', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // With `validUntil` + !`holderRevocable` credential.validUntil = Timestamp.fromDate( @@ -188,7 +189,7 @@ describe('registerCredential', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // With data const auxData = Buffer.from('Hello world!').toString('hex'); @@ -203,7 +204,7 @@ describe('registerCredential', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); }); }); @@ -232,7 +233,7 @@ describe('registerRevocationKeys', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // Multilple keys tx = cis4.createRegisterRevocationKeys( @@ -244,7 +245,7 @@ describe('registerRevocationKeys', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // With data tx = cis4.createRegisterRevocationKeys( @@ -257,7 +258,7 @@ describe('registerRevocationKeys', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); }); }); @@ -285,7 +286,7 @@ describe('removeRevocationKeys', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // Multiple keys tx = cis4.createRemoveRevocationKeys( @@ -297,7 +298,7 @@ describe('removeRevocationKeys', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // With data tx = cis4.createRemoveRevocationKeys( @@ -310,7 +311,7 @@ describe('removeRevocationKeys', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); }); }); @@ -341,7 +342,7 @@ describe('revokeCredentialAsIssuer', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // With reason tx = cis4.createRevokeCredentialAsIssuer( @@ -355,7 +356,7 @@ describe('revokeCredentialAsIssuer', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // With data tx = cis4.createRevokeCredentialAsIssuer( @@ -369,7 +370,7 @@ describe('revokeCredentialAsIssuer', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); }); }); @@ -404,7 +405,7 @@ describe('revokeCredentialAsHolder', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // With reason tx = await cis4.createRevokeCredentialAsHolder( @@ -419,7 +420,7 @@ describe('revokeCredentialAsHolder', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); }); }); @@ -456,7 +457,7 @@ describe('revokeCredentialAsOther', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); // With reason tx = await cis4.createRevokeCredentialAsOther( @@ -472,6 +473,6 @@ describe('revokeCredentialAsOther', () => { Buffer.from(tx.schema.value, 'base64'), true ); - expect(tx.parameter.hex).toEqual(schemaSerial.toString('hex')); + expect(tx.parameter.hex).toEqual(Parameter.toHexString(schemaSerial)); }); }); diff --git a/packages/nodejs/test/clientV2.test.ts b/packages/nodejs/test/clientV2.test.ts index ba18f4bee..8195ac7df 100644 --- a/packages/nodejs/test/clientV2.test.ts +++ b/packages/nodejs/test/clientV2.test.ts @@ -769,8 +769,8 @@ test.each([clientV2, clientWeb])('getEmbeddedSchema', async (client) => { const returnValue = deserializeReceiveReturnValue( v1.ReturnValue.toBuffer(rawReturnValue), schema, - 'weather', - 'get' + v1.ContractName.fromStringUnchecked('weather'), + v1.EntrypointName.fromStringUnchecked('get') ); expect(returnValue).toEqual({ Sunny: [] }); } else { diff --git a/packages/nodejs/test/deserialization.test.ts b/packages/nodejs/test/deserialization.test.ts index d61d60070..6727643dc 100644 --- a/packages/nodejs/test/deserialization.test.ts +++ b/packages/nodejs/test/deserialization.test.ts @@ -1,5 +1,9 @@ import { getNodeClient } from './testHelpers.js'; -import { ContractAddress, isInstanceInfoV0 } from '@concordium/common-sdk'; +import { + ContractAddress, + ContractName, + isInstanceInfoV0, +} from '@concordium/common-sdk'; import * as fs from 'fs'; import { deserializeContractState } from '@concordium/common-sdk/schema'; @@ -29,7 +33,7 @@ test.skip('Deserialize state with schema from file (two-step-transfer)', async ( fs.readFileSync('./test/resources/two-step-transfer-schema.bin') ); const state = deserializeContractState( - 'two-step-transfer', + ContractName.fromStringUnchecked('two-step-transfer'), schema, instanceInfo.model );