diff --git a/packages/common/src/GenericContract.ts b/packages/common/src/GenericContract.ts index 5f9716ddd..8d8eb3cb9 100644 --- a/packages/common/src/GenericContract.ts +++ b/packages/common/src/GenericContract.ts @@ -131,15 +131,12 @@ export class ContractDryRun { blockHash?: BlockHash.Type ): Promise { const parameter = Parameter.fromBuffer(serializer(input)); - - const method = ReceiveName.create(this.contractName, entrypoint); - return this.grpcClient.invokeContract( { contract: this.contractAddress, parameter, invoker, - method: ReceiveName.toString(method), + method: ReceiveName.create(this.contractName, entrypoint), }, blockHash ); @@ -471,7 +468,7 @@ class ContractBase { * @returns {R} The transaction hash of the update transaction */ public async invokeView( - entrypoint: V, + entrypoint: EntrypointName.Type, serializeInput: (input: T) => ArrayBuffer, deserializeResponse: (value: HexString) => R, input: T, @@ -483,7 +480,7 @@ class ContractBase { { contract: this.contractAddress, parameter, - method: `${this.contractName}.${entrypoint}`, + method: ReceiveName.create(this.contractName, entrypoint), }, blockHash ); diff --git a/packages/common/src/cis0.ts b/packages/common/src/cis0.ts index 68adfe74d..eb0916b60 100644 --- a/packages/common/src/cis0.ts +++ b/packages/common/src/cis0.ts @@ -14,6 +14,7 @@ import * as Parameter from './types/Parameter.js'; import * as ContractName from './types/ContractName.js'; import * as ReceiveName from './types/ReceiveName.js'; import * as ReturnValue from './types/ReturnValue.js'; +import { EntrypointName } from './index.js'; /** * Namespace with types for CIS-0 standard contracts @@ -142,14 +143,16 @@ export async function cis0Supports( ); }); - const contractName = ContractName.toString( - ContractName.fromInitName(instanceInfo.name) + const contractName = ContractName.fromInitName(instanceInfo.name); + const supportReceiveName = ReceiveName.create( + contractName, + EntrypointName.fromStringUnchecked('supports') ); if ( - !instanceInfo.methods - .map(ReceiveName.toString) - .includes(`${contractName}.supports`) + !instanceInfo.methods.some((methods) => + ReceiveName.equals(methods, supportReceiveName) + ) ) { return undefined; } @@ -162,7 +165,7 @@ export async function cis0Supports( { contract: contractAddress, parameter, - method: `${contractName}.supports`, + method: supportReceiveName, }, blockHash ); diff --git a/packages/common/src/cis2/CIS2Contract.ts b/packages/common/src/cis2/CIS2Contract.ts index cd115b459..b5f8fc1d5 100644 --- a/packages/common/src/cis2/CIS2Contract.ts +++ b/packages/common/src/cis2/CIS2Contract.ts @@ -57,7 +57,7 @@ class CIS2DryRun extends ContractDryRun { * * @param {CIS2.Address} sender - Address of the sender of the transfer. * @param {CIS2.Transfer | CIS2.Transfer[]} transfer(s) - The transfer object(s). - * @param {HexString} [blockHash] - The hash of the block to perform the invocation of. Defaults to the latest finalized block on chain. + * @param {BlockHash.Type} [blockHash] - The hash of the block to perform the invocation of. Defaults to the latest finalized block on chain. * * @returns {InvokeContractResult} the contract invocation result, which includes whether or not the invocation succeeded along with the energy spent. */ @@ -394,7 +394,7 @@ export class CIS2Contract extends CISContract { deserializeCIS2BalanceOfResponse ); return this.invokeView( - 'balanceOf', + EntrypointName.fromStringUnchecked('balanceOf'), serialize, deserialize, queries, @@ -441,7 +441,7 @@ export class CIS2Contract extends CISContract { deserializeCIS2OperatorOfResponse ); return this.invokeView( - 'operatorOf', + EntrypointName.fromStringUnchecked('operatorOf'), serialize, deserialize, queries, @@ -488,7 +488,7 @@ export class CIS2Contract extends CISContract { deserializeCIS2TokenMetadataResponse ); return this.invokeView( - 'tokenMetadata', + EntrypointName.fromStringUnchecked('tokenMetadata'), serialize, deserialize, tokenIds, diff --git a/packages/common/src/cis4/CIS4Contract.ts b/packages/common/src/cis4/CIS4Contract.ts index a069886b4..77e6da61d 100644 --- a/packages/common/src/cis4/CIS4Contract.ts +++ b/packages/common/src/cis4/CIS4Contract.ts @@ -331,7 +331,7 @@ export class CIS4Contract extends CISContract { blockHash?: BlockHash.Type ): Promise { return this.invokeView( - 'credentialEntry', + EntrypointName.fromStringUnchecked('credentialEntry'), (k) => Buffer.from(k, 'hex'), deserializeCIS4CredentialEntry, credHolderPubKey, @@ -352,7 +352,7 @@ export class CIS4Contract extends CISContract { blockHash?: BlockHash.Type ): Promise { return this.invokeView( - 'credentialStatus', + EntrypointName.fromStringUnchecked('credentialStatus'), (k) => Buffer.from(k, 'hex'), deserializeCIS4CredentialStatus, credHolderPubKey, @@ -371,7 +371,7 @@ export class CIS4Contract extends CISContract { blockHash?: BlockHash.Type ): Promise { return this.invokeView( - 'revocationKeys', + EntrypointName.fromStringUnchecked('revocationKeys'), () => Buffer.alloc(0), deserializeCIS4RevocationKeys, undefined, @@ -390,7 +390,7 @@ export class CIS4Contract extends CISContract { blockHash?: BlockHash.Type ): Promise { return this.invokeView( - 'registryMetadata', + EntrypointName.fromStringUnchecked('registryMetadata'), () => Buffer.alloc(0), deserializeCIS4MetadataResponse, undefined, @@ -407,7 +407,7 @@ export class CIS4Contract extends CISContract { */ public issuer(blockHash?: BlockHash.Type): Promise { return this.invokeView( - 'issuer', + EntrypointName.fromStringUnchecked('issuer'), () => Buffer.alloc(0), (value) => value, undefined, diff --git a/packages/common/src/grpc/GRPCClient.ts b/packages/common/src/grpc/GRPCClient.ts index 811ae154a..e7c5dd478 100644 --- a/packages/common/src/grpc/GRPCClient.ts +++ b/packages/common/src/grpc/GRPCClient.ts @@ -40,6 +40,7 @@ import * as ContractAddress from '../types/ContractAddress.js'; import * as Parameter from '../types/Parameter.js'; import * as Energy from '../types/Energy.js'; import * as SequenceNumber from '../types/SequenceNumber.js'; +import * as ReceiveName from '../types/ReceiveName.js'; /** * @hidden @@ -293,7 +294,7 @@ export class ConcordiumGRPCClient { invoker: getInvokerInput(context.invoker), instance: context.contract, amount: { value: context.amount?.microCcdAmount || 0n }, - entrypoint: { value: context.method }, + entrypoint: ReceiveName.toProto(context.method), parameter: Parameter.toProto( context.parameter ?? Parameter.empty() ), @@ -1564,9 +1565,7 @@ export function getAccountIdentifierInput( if (AccountAddress.isAccountAddress(accountIdentifier)) { returnIdentifier = { oneofKind: 'address', - address: { - value: AccountAddress.toBuffer(accountIdentifier), - }, + address: AccountAddress.toProto(accountIdentifier), }; } else if ( CredentialRegistrationId.isCredentialRegistrationId(accountIdentifier) diff --git a/packages/common/src/grpc/translation.ts b/packages/common/src/grpc/translation.ts index 312285d76..07b26ae51 100644 --- a/packages/common/src/grpc/translation.ts +++ b/packages/common/src/grpc/translation.ts @@ -277,7 +277,9 @@ function translateChainParametersCommon( euroPerEnergy: unwrap(params.euroPerEnergy?.value), microGTUPerEuro: unwrap(params.microCcdPerEuro?.value), accountCreationLimit: unwrap(params.accountCreationLimit?.value), - foundationAccount: unwrapToBase58(params.foundationAccount), + foundationAccount: AccountAddress.fromProto( + unwrap(params.foundationAccount) + ), level1Keys: trHigherLevelKeysUpdate(unwrap(params.level1Keys)), rootKeys: trHigherLevelKeysUpdate(unwrap(params.rootKeys)), }; @@ -1895,7 +1897,7 @@ function trAccountTransactionSummary( unwrap(contractInit.address) ), amount: unwrap(contractInit.amount?.value), - initName: unwrap(contractInit.initName?.value), + initName: InitName.fromProto(unwrap(contractInit.initName)), events: unwrap(contractInit.events.map(unwrapValToHex)), contractVersion: unwrap(contractInit.contractVersion), ref: unwrapValToHex(contractInit.originRef), @@ -2387,7 +2389,7 @@ export function delegatorInfo( delegatorInfo: v2.DelegatorInfo ): v1.DelegatorInfo { return { - account: unwrapToBase58(delegatorInfo.account), + account: AccountAddress.fromProto(unwrap(delegatorInfo.account)), stake: unwrap(delegatorInfo.stake?.value), ...(delegatorInfo.pendingChange && { pendingChange: trPendingChange(delegatorInfo.pendingChange), @@ -2397,7 +2399,7 @@ export function delegatorInfo( export function branch(branchV2: v2.Branch): v1.Branch { return { - blockHash: unwrapValToHex(branchV2.blockHash), + blockHash: BlockHash.fromProto(unwrap(branchV2.blockHash)), children: branchV2.children.map(branch), }; } @@ -2407,7 +2409,7 @@ function trBakerElectionInfo( ): v1.BakerElectionInfo { return { baker: unwrap(bakerElectionInfo.baker?.value), - account: unwrapToBase58(bakerElectionInfo.account), + account: AccountAddress.fromProto(unwrap(bakerElectionInfo.account)), lotteryPower: bakerElectionInfo.lotteryPower, }; } diff --git a/packages/common/src/json-rpc/JsonRpcClient.ts b/packages/common/src/json-rpc/JsonRpcClient.ts index a7b2d86c3..62121a5d2 100644 --- a/packages/common/src/json-rpc/JsonRpcClient.ts +++ b/packages/common/src/json-rpc/JsonRpcClient.ts @@ -373,6 +373,7 @@ export class JsonRpcClient { const context = { ...contractContext, invoker, + method: contractContext.method.value, energy: contractContext.energy === undefined ? undefined diff --git a/packages/common/src/pub/types.ts b/packages/common/src/pub/types.ts index c978e0af7..18b365cc8 100644 --- a/packages/common/src/pub/types.ts +++ b/packages/common/src/pub/types.ts @@ -64,6 +64,7 @@ import * as AccountAddress from '../types/AccountAddress.js'; import * as ContractAddress from '../types/ContractAddress.js'; import * as EntrypointName from '../types/EntrypointName.js'; import * as Timestamp from '../types/Timestamp.js'; +import * as Duration from '../types/Duration.js'; // These cannot be exported directly as modules because of a bug in an eslint plugin. // https://github.com/import-js/eslint-plugin-import/issues/2289. @@ -83,4 +84,5 @@ export { ContractAddress, EntrypointName, Timestamp, + Duration, }; diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 31ecae192..faa5ae3e7 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -460,7 +460,7 @@ export interface ChainParametersCommon { /** Limit for the number of account creations in a block */ accountCreationLimit: number; /** The chain foundation account */ - foundationAccount: Base58String; + foundationAccount: AccountAddress.Type; /** The chain foundation account index */ foundationAccountIndex?: bigint; /** Keys allowed to do level1 updates */ @@ -1408,7 +1408,7 @@ export interface ArInfo { } interface DelegatorInfoCommon { - account: Base58String; + account: AccountAddress.Type; stake: Amount; } export interface DelegatorInfo extends DelegatorInfoCommon { @@ -1418,13 +1418,13 @@ export interface DelegatorInfo extends DelegatorInfoCommon { export type DelegatorRewardPeriodInfo = DelegatorInfoCommon; export interface Branch { - blockHash: HexString; + blockHash: BlockHash.Type; children: Branch[]; } export interface BakerElectionInfo { baker: BakerId; - account: Base58String; + account: AccountAddress.Type; lotteryPower: number; } @@ -1842,7 +1842,7 @@ export interface ContractContext { invoker?: ContractAddress.Type | AccountAddress.Type; contract: ContractAddress.Type; amount?: CcdAmount; - method: string; + method: ReceiveName.Type; parameter?: Parameter.Type; energy?: Energy.Type; } diff --git a/packages/common/src/types/AccountAddress.ts b/packages/common/src/types/AccountAddress.ts index 83ff8ed05..67c1c1852 100644 --- a/packages/common/src/types/AccountAddress.ts +++ b/packages/common/src/types/AccountAddress.ts @@ -79,8 +79,8 @@ export function fromBase58(address: string): AccountAddress { `The provided address '${address}' does not use version byte with value of 1` ); } - const decodedAddress = buffer.subarray(1); - return new AccountAddress(address, decodedAddress); + const decodedAddress = buffer.subarray(1, 33); // Ensure only the 32 bytes for the address is kept. + return new AccountAddress(address, new Uint8Array(decodedAddress)); } /** @@ -180,3 +180,13 @@ export function toProto(accountAddress: AccountAddress): Proto.AccountAddress { value: accountAddress.decodedAddress, }; } + +/** + * Check if two account addresses are the exact same. This will not consider different aliases for the same account as equal. + * @param {AccountAddress} left + * @param {AccountAddress} right + * @returns {boolean} True if they are equal. + */ +export function equals(left: AccountAddress, right: AccountAddress): boolean { + return left.address === right.address; +} diff --git a/packages/common/src/types/BlockHash.ts b/packages/common/src/types/BlockHash.ts index 8fffd96f1..1d60b226a 100644 --- a/packages/common/src/types/BlockHash.ts +++ b/packages/common/src/types/BlockHash.ts @@ -1,6 +1,11 @@ import type { HexString } from '../types.js'; import type * as Proto from '../grpc-api/v2/concordium/types.js'; +/** + * The number of bytes used to represent a block hash. + */ +const blockHashByteLength = 32; + /** * Represents a hash of a block in the chain. */ @@ -25,7 +30,7 @@ export type Type = BlockHash; * @returns {BlockHash} */ export function fromBuffer(buffer: ArrayBuffer): BlockHash { - if (buffer.byteLength !== 32) { + if (buffer.byteLength !== blockHashByteLength) { throw new Error( `Invalid transaction hash provided: Expected a buffer containing 32 bytes, instead got '${Buffer.from( buffer @@ -93,3 +98,18 @@ export function toBlockHashInput(blockHash: BlockHash): Proto.BlockHashInput { blockHashInput: { oneofKind: 'given', given: toProto(blockHash) }, }; } + +/** + * Check if two transaction hashes are the same. + * @param {BlockHash} left + * @param {BlockHash} right + * @returns {boolean} True if they are equal. + */ +export function equals(left: BlockHash, right: BlockHash): boolean { + for (let i = 0; i < blockHashByteLength; i++) { + if (left.buffer.at(i) !== right.buffer.at(i)) { + return false; + } + } + return true; +} diff --git a/packages/common/src/types/ContractAddress.ts b/packages/common/src/types/ContractAddress.ts index 301ef8d4b..4da00b135 100644 --- a/packages/common/src/types/ContractAddress.ts +++ b/packages/common/src/types/ContractAddress.ts @@ -96,3 +96,13 @@ export function toProto( subindex: contractAddress.subindex, }; } + +/** + * Check if two contract addresses are the same. + * @param {ContractAddress} left + * @param {ContractAddress} right + * @returns {boolean} True if they are equal. + */ +export function equals(left: ContractAddress, right: ContractAddress): boolean { + return left.index === right.index && left.subindex === right.subindex; +} diff --git a/packages/common/src/types/CredentialRegistrationId.ts b/packages/common/src/types/CredentialRegistrationId.ts index cd4ed52bb..8108f98cd 100644 --- a/packages/common/src/types/CredentialRegistrationId.ts +++ b/packages/common/src/types/CredentialRegistrationId.ts @@ -76,7 +76,7 @@ export function isCredentialRegistrationId( typeof input.credId === 'string' && input.credId.length === 96 && isHex(input.credId) && - (parseInt(input.credId.substring(0, 2), 16) & 0b10000000) === 0 + (parseInt(input.credId.substring(0, 2), 16) & 0b10000000) !== 0 ); } diff --git a/packages/common/src/types/ReceiveName.ts b/packages/common/src/types/ReceiveName.ts index 769cb32ec..d985c1f17 100644 --- a/packages/common/src/types/ReceiveName.ts +++ b/packages/common/src/types/ReceiveName.ts @@ -150,3 +150,13 @@ export function toProto(receiveName: ReceiveName): Proto.ReceiveName { value: receiveName.value, }; } + +/** + * Check if two smart contract receive names represent the same. + * @param {ReceiveName} left + * @param {ReceiveName} right + * @returns {boolean} True if they are equal. + */ +export function equals(left: ReceiveName, right: ReceiveName): boolean { + return left.value === right.value; +} diff --git a/packages/common/src/types/ReturnValue.ts b/packages/common/src/types/ReturnValue.ts index 424ca7ea7..9535a8d6f 100644 --- a/packages/common/src/types/ReturnValue.ts +++ b/packages/common/src/types/ReturnValue.ts @@ -36,6 +36,15 @@ export function fromBuffer(buffer: ArrayBuffer): ReturnValue { return new ReturnValue(new Uint8Array(buffer)); } +/** + * Create a return type from invoking a smart contract entrypoint from a hex string. + * @param {HexString} hex The hex string representing the return value. + * @returns {ReturnValue} + */ +export function fromHexString(hex: HexString): ReturnValue { + return new ReturnValue(new Uint8Array(Buffer.from(hex, 'hex'))); +} + /** * Convert a return value into a hex string. * @param {ReturnValue} returnValue The return value to encode in a hex string. diff --git a/packages/common/src/types/TransactionHash.ts b/packages/common/src/types/TransactionHash.ts index 53a69e0ea..8c842b933 100644 --- a/packages/common/src/types/TransactionHash.ts +++ b/packages/common/src/types/TransactionHash.ts @@ -1,6 +1,11 @@ import type { HexString } from '../types.js'; import type * as Proto from '../grpc-api/v2/concordium/types.js'; +/** + * The number of bytes used to represent a transaction hash. + */ +const transactionHashByteLength = 32; + /** Hash of a transaction. */ class TransactionHash { /** Having a private field prevents similar structured objects to be considered the same type (similar to nominal typing). */ @@ -21,7 +26,7 @@ export type Type = TransactionHash; * @returns {TransactionHash} */ export function fromBuffer(buffer: ArrayBuffer): TransactionHash { - if (buffer.byteLength !== 32) { + if (buffer.byteLength !== transactionHashByteLength) { throw new Error( `Invalid transaction hash provided: Expected a buffer containing 32 bytes, instead got '${Buffer.from( buffer @@ -82,3 +87,18 @@ export function toProto( value: transactionHash.buffer, }; } + +/** + * Check if two transaction hashes are the same. + * @param {TransactionHash} left + * @param {TransactionHash} right + * @returns {boolean} True if they are equal. + */ +export function equals(left: TransactionHash, right: TransactionHash): boolean { + for (let i = 0; i < transactionHashByteLength; i++) { + if (left.buffer.at(i) !== right.buffer.at(i)) { + return false; + } + } + return true; +} diff --git a/packages/common/src/types/blockItemSummary.ts b/packages/common/src/types/blockItemSummary.ts index 0eeff9247..c0c186995 100644 --- a/packages/common/src/types/blockItemSummary.ts +++ b/packages/common/src/types/blockItemSummary.ts @@ -32,7 +32,7 @@ import { RejectReason } from './rejectReason.js'; import { isDefined } from '../util.js'; import { isEqualContractAddress } from '../contractHelpers.js'; import type * as ContractAddress from './ContractAddress.js'; -import type * as AccountAddress from './AccountAddress.js'; +import * as AccountAddress from './AccountAddress.js'; import type * as BlockHash from './BlockHash.js'; import type * as TransactionHash from './TransactionHash.js'; import type * as Energy from './Energy.js'; @@ -504,7 +504,12 @@ export function affectedAccounts( if ( event.tag === TransactionEventTag.Transferred && event.to.type === 'AddressAccount' && - !addresses.includes(event.to.address) + !addresses.some( + AccountAddress.equals.bind( + undefined, + event.to.address + ) + ) ) { return [...addresses, event.to.address]; } @@ -516,7 +521,10 @@ export function affectedAccounts( default: { const receiver = getReceiverAccount(summary); - if (summary.sender === receiver || receiver === undefined) { + if ( + receiver === undefined || + AccountAddress.equals(summary.sender, receiver) + ) { return [summary.sender]; } diff --git a/packages/common/src/types/transactionEvent.ts b/packages/common/src/types/transactionEvent.ts index a57476fb4..09f21ebf5 100644 --- a/packages/common/src/types/transactionEvent.ts +++ b/packages/common/src/types/transactionEvent.ts @@ -15,6 +15,7 @@ import type * as ContractAddress from './ContractAddress.js'; import type * as AccountAddress from './AccountAddress.js'; import type * as Parameter from './Parameter.js'; import type * as ReceiveName from './ReceiveName.js'; +import type * as InitName from './InitName.js'; export enum TransactionEventTag { ModuleDeployed = 'ModuleDeployed', @@ -131,7 +132,7 @@ export interface ContractInitializedEvent { tag: TransactionEventTag.ContractInitialized; address: ContractAddress.Type; amount: Amount; - initName: string; + initName: InitName.Type; events: HexString[]; contractVersion: ContractVersion; ref: ModuleRef; diff --git a/packages/common/test/HdWallet.test.ts b/packages/common/test/HdWallet.test.ts index 58db3c33b..7e670a89c 100644 --- a/packages/common/test/HdWallet.test.ts +++ b/packages/common/test/HdWallet.test.ts @@ -1,4 +1,6 @@ +import { ContractAddress } from '../src/index.js'; import { ConcordiumHdWallet } from '../src/wasm/HdWallet.js'; +import { Buffer } from 'buffer/index.js'; export const TEST_SEED_1 = 'efa5e27326f8fa0902e647b52449bf335b7b605adc387015ec903f41d95080eb71361cbc7fb78721dcd4f3926a337340aa1406df83332c44c1cdcfe100603860'; import * as ed from '@noble/ed25519'; @@ -190,7 +192,10 @@ test('Testnet CredId matches credDeployment test', () => { test('Mainnet verifiable credential signing key', () => { const wallet = ConcordiumHdWallet.fromHex(TEST_SEED_1, 'Mainnet'); expect( - wallet.getVerifiableCredentialSigningKey({ index: 1n, subindex: 2n }, 1) + wallet.getVerifiableCredentialSigningKey( + ContractAddress.create(1n, 2n), + 1 + ) ).toEqual( Buffer.from( '670d904509ce09372deb784e702d4951d4e24437ad3879188d71ae6db51f3301', @@ -203,7 +208,7 @@ test('Mainnet verifiable credential public key', () => { const wallet = ConcordiumHdWallet.fromHex(TEST_SEED_1, 'Mainnet'); expect( wallet.getVerifiableCredentialPublicKey( - { index: 3n, subindex: 1232n }, + ContractAddress.create(3, 1232), 341 ) ).toEqual( @@ -217,10 +222,7 @@ test('Mainnet verifiable credential public key', () => { test('Testnet verifiable credential signing key', () => { const wallet = ConcordiumHdWallet.fromHex(TEST_SEED_1, 'Testnet'); expect( - wallet.getVerifiableCredentialSigningKey( - { index: 13n, subindex: 0n }, - 1 - ) + wallet.getVerifiableCredentialSigningKey(ContractAddress.create(13), 1) ).toEqual( Buffer.from( 'c75a161b97a1e204d9f31202308958e541e14f0b14903bd220df883bd06702bb', @@ -232,10 +234,7 @@ test('Testnet verifiable credential signing key', () => { test('Testnet verifiable credential public key', () => { const wallet = ConcordiumHdWallet.fromHex(TEST_SEED_1, 'Testnet'); expect( - wallet.getVerifiableCredentialPublicKey( - { index: 17n, subindex: 0n }, - 341 - ) + wallet.getVerifiableCredentialPublicKey(ContractAddress.create(17), 341) ).toEqual( Buffer.from( 'c52a30475bac88da9e65471cf9cf59f99dcce22ce31de580b3066597746b394a', diff --git a/packages/common/test/accountTransactions.test.ts b/packages/common/test/accountTransactions.test.ts index fc03e2e73..47e09a9ce 100644 --- a/packages/common/test/accountTransactions.test.ts +++ b/packages/common/test/accountTransactions.test.ts @@ -7,6 +7,8 @@ import { CcdAmount, ConfigureBakerPayload, getAccountTransactionSignDigest, + AccountTransactionHeader, + SequenceNumber, } from '../src/index.js'; test('configureBaker is serialized correctly', async () => { @@ -18,9 +20,9 @@ test('configureBaker is serialized correctly', async () => { const expiry = new TransactionExpiry(new Date(1675872215), true); - const header = { + const header: AccountTransactionHeader = { expiry, - nonce: 1n, + nonce: SequenceNumber.create(1), sender: AccountAddress.fromBase58(senderAccountAddress), }; diff --git a/packages/common/test/deserialization.test.ts b/packages/common/test/deserialization.test.ts index 34040455f..06be595e2 100644 --- a/packages/common/test/deserialization.test.ts +++ b/packages/common/test/deserialization.test.ts @@ -16,7 +16,11 @@ import { TransactionExpiry, tokenAddressFromBase58, tokenAddressToBase58, + SequenceNumber, + CIS2, + ContractAddress, } from '../src/index.js'; +import { expectToEqual } from './testHelpers.js'; function deserializeAccountTransactionBase( type: AccountTransactionType, @@ -25,7 +29,7 @@ function deserializeAccountTransactionBase( ) { const header: AccountTransactionHeader = { expiry, - nonce: 0n, + nonce: SequenceNumber.create(1), sender: AccountAddress.fromBase58( '3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt' ), @@ -51,7 +55,7 @@ function deserializeAccountTransactionBase( throw new Error('Incorrect BlockItemKind'); } - expect(deserialized.transaction).toEqual({ + expectToEqual(deserialized.transaction, { accountTransaction: transaction, signatures, }); @@ -109,11 +113,8 @@ test('Test parsing of Token Addresses', () => { let base58 = '5Pxr5EUtU'; let address = tokenAddressFromBase58(base58); let rebase58 = tokenAddressToBase58(address); - let expectedAddress = { - contract: { - index: 0n, - subindex: 0n, - }, + let expectedAddress: CIS2.TokenAddress = { + contract: ContractAddress.create(0), id: '', }; expect(address).toEqual(expectedAddress); @@ -123,10 +124,7 @@ test('Test parsing of Token Addresses', () => { address = tokenAddressFromBase58(base58); rebase58 = tokenAddressToBase58(address); expectedAddress = { - contract: { - index: 0n, - subindex: 0n, - }, + contract: ContractAddress.create(0), id: 'aa', }; expect(address).toEqual(expectedAddress); @@ -136,10 +134,7 @@ test('Test parsing of Token Addresses', () => { address = tokenAddressFromBase58(base58); rebase58 = tokenAddressToBase58(address); const expectedAddress2 = { - contract: { - index: 1n, - subindex: 0n, - }, + contract: ContractAddress.create(1), id: '', }; expect(address).toEqual(expectedAddress2); @@ -149,10 +144,7 @@ test('Test parsing of Token Addresses', () => { address = tokenAddressFromBase58(base58); rebase58 = tokenAddressToBase58(address); expectedAddress = { - contract: { - index: 1n, - subindex: 0n, - }, + contract: ContractAddress.create(1), id: 'aa', }; expect(address).toEqual(expectedAddress); @@ -162,10 +154,7 @@ test('Test parsing of Token Addresses', () => { address = tokenAddressFromBase58(base58); rebase58 = tokenAddressToBase58(address); expectedAddress = { - contract: { - index: 1n, - subindex: 0n, - }, + contract: ContractAddress.create(1), id: '0a', }; expect(address).toEqual(expectedAddress); diff --git a/packages/common/test/resources/expectedStatements.ts b/packages/common/test/resources/expectedStatements.ts index 5f32bad25..c454ce176 100644 --- a/packages/common/test/resources/expectedStatements.ts +++ b/packages/common/test/resources/expectedStatements.ts @@ -1,3 +1,4 @@ +import { ContractAddress } from '../../src/index.js'; import { CredentialStatement } from '../../src/web3-id/web3IdProofTypes.js'; export const expectedStatementMixed: CredentialStatement[] = [ @@ -5,8 +6,8 @@ export const expectedStatementMixed: CredentialStatement[] = [ idQualifier: { type: 'sci', issuers: [ - { index: 2101n, subindex: 0n }, - { index: 1337n, subindex: 42n }, + ContractAddress.create(2101), + ContractAddress.create(1337, 42), ], }, statement: [ @@ -26,7 +27,7 @@ export const expectedStatementMixed: CredentialStatement[] = [ { idQualifier: { type: 'sci', - issuers: [{ index: 1338n, subindex: 0n }], + issuers: [ContractAddress.create(1338, 0)], }, statement: [ { diff --git a/packages/common/test/serialization.test.ts b/packages/common/test/serialization.test.ts index a592ff6fa..7e0c667a5 100644 --- a/packages/common/test/serialization.test.ts +++ b/packages/common/test/serialization.test.ts @@ -12,6 +12,7 @@ import { SimpleTransferPayload, } from '../src/types.js'; import { TransactionExpiry } from '../src/types/transactionExpiry.js'; +import { SequenceNumber } from '../src/index.js'; test('fail account transaction serialization if no signatures', () => { const simpleTransferPayload: SimpleTransferPayload = { @@ -23,7 +24,7 @@ test('fail account transaction serialization if no signatures', () => { const header: AccountTransactionHeader = { expiry: new TransactionExpiry(new Date(Date.now() + 1200000)), - nonce: 0n, + nonce: SequenceNumber.create(1), sender: AccountAddress.fromBase58( '3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt' ), diff --git a/packages/common/test/signHelpers.test.ts b/packages/common/test/signHelpers.test.ts index 22a3a4343..19b987970 100644 --- a/packages/common/test/signHelpers.test.ts +++ b/packages/common/test/signHelpers.test.ts @@ -10,9 +10,12 @@ import { SimpleAccountKeys, } from '../src/index.js'; -const TEST_ACCOUNT_SINGLE = - '3eP94feEdmhYiPC1333F9VoV31KGMswonuHk5tqmZrzf761zK5'; -const TEST_ACCOUNT_MULTI = '4hTGW1Uz6u2hUgEtwWjJUdZQncVpHGWZPgGdRpgL1VNn5NzyHd'; +const TEST_ACCOUNT_SINGLE = AccountAddress.fromBase58( + '3eP94feEdmhYiPC1333F9VoV31KGMswonuHk5tqmZrzf761zK5' +); +const TEST_ACCOUNT_MULTI = AccountAddress.fromBase58( + '4hTGW1Uz6u2hUgEtwWjJUdZQncVpHGWZPgGdRpgL1VNn5NzyHd' +); const TEST_KEY_SINGLE = 'e1cf504954663e49f4fe884c7c35415b09632cccd82d3d2a62ab2825e67d785d'; @@ -76,14 +79,14 @@ const testEachMessageType = test.each(['test', Buffer.from('test', 'utf8')]); testEachMessageType('[%o] test signMessage', async (message) => { const sign = () => signMessage(account, message, signer); - let account = AccountAddress.fromBase58(TEST_ACCOUNT_SINGLE); + let account = TEST_ACCOUNT_SINGLE; let signer = buildBasicAccountSigner(TEST_KEY_SINGLE); let signature = await sign(); expect(signature[0][0]).toBe( '445197d79ca90d8cc8440328dac9f307932ade0c03cc7aa575b59b746e26e5f1bca13ade5ff7a56e918ba5a32450fdf52b034cd2580929b21213263e81f7f809' ); - account = AccountAddress.fromBase58(TEST_ACCOUNT_MULTI); + account = TEST_ACCOUNT_MULTI; signer = buildAccountSigner(TEST_KEYS_MULTI); signature = await sign(); @@ -143,8 +146,9 @@ test('verifyMessageSignature returns false on the incorrect address', async () = }, }, { - accountAddress: - '3dbRxtzhb8MotFBgH5DcdFJy7t4we4N8Ep6Mxdha8XvLhq7YmZ', + accountAddress: AccountAddress.fromBase58( + '3dbRxtzhb8MotFBgH5DcdFJy7t4we4N8Ep6Mxdha8XvLhq7YmZ' + ), accountThreshold: 1, accountCredentials: TEST_CREDENTIALS_SINGLE, } as unknown as AccountInfo diff --git a/packages/common/test/testHelpers.ts b/packages/common/test/testHelpers.ts new file mode 100644 index 000000000..2915d0895 --- /dev/null +++ b/packages/common/test/testHelpers.ts @@ -0,0 +1,67 @@ +import { AccountAddress } from '../src/index.js'; + +type OverrideCheck = { + when: (a: unknown) => boolean; + check: (l: A, r: A) => boolean; +}; + +const checkBuffers: OverrideCheck = { + when(u) { + return u instanceof ArrayBuffer; + }, + check(l, r) { + if (l.byteLength !== r.byteLength) { + return false; + } + const lu8 = new Uint8Array(l); + const ru8 = new Uint8Array(r); + for (let i = 0; i < l.byteLength; i++) { + if (lu8.at(i) !== ru8.at(i)) { + return false; + } + } + return true; + }, +}; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const equalOverrides: OverrideCheck[] = [ + { + when: AccountAddress.isAccountAddress, + check: AccountAddress.equals, + }, + checkBuffers, +]; + +export function expectToEqual(value: A, expected: A) { + const override = equalOverrides.find(({ when: guard }) => guard(expected)); + if (override !== undefined) { + if (!override.when(value)) { + throw new Error(`Expected: ${expected} instead got ${value}`); + } + if (!override.check(value, expected)) { + throw new Error( + `Expected:\n ${JSON.stringify( + expected + )}\n\nInstead got:\n ${JSON.stringify(value)}` + ); + } + } else if (Array.isArray(expected)) { + if (!Array.isArray(value) || value.length !== expected.length) { + throw new Error(`Expected: ${expected} instead got ${value}`); + } + for (let i = 0; i < expected.length; i++) { + expectToEqual(value[i], expected[i]); + } + } else if (typeof expected === 'object' && expected !== null) { + for (const key of Object.keys(expected)) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + expectToEqual(value[key], expected[key]); + } + } else { + if (value !== expected) { + expect(value).toBe(expected); + } + } +} diff --git a/packages/common/test/types/AccountAddress.test.ts b/packages/common/test/types/AccountAddress.test.ts new file mode 100644 index 000000000..d1a326b74 --- /dev/null +++ b/packages/common/test/types/AccountAddress.test.ts @@ -0,0 +1,17 @@ +import { AccountAddress } from '../../src/index.js'; + +test('Base58 decode-encode results is the same', () => { + const address = AccountAddress.fromBuffer(new Uint8Array(32)); + const base58 = AccountAddress.toBase58(address); + const converted = AccountAddress.fromBase58(base58); + expect(AccountAddress.equals(converted, address)).toBeTruthy(); +}); + +test('Buffer encode-decode results is the same', () => { + const address = AccountAddress.fromBase58( + '3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt' + ); + const buffer = AccountAddress.toBuffer(address); + const converted = AccountAddress.fromBuffer(buffer); + expect(AccountAddress.equals(converted, address)).toBeTruthy(); +}); diff --git a/packages/common/test/types/blockItemSummary.test.ts b/packages/common/test/types/blockItemSummary.test.ts index cf3b62ff0..bccefd864 100644 --- a/packages/common/test/types/blockItemSummary.test.ts +++ b/packages/common/test/types/blockItemSummary.test.ts @@ -20,13 +20,23 @@ import { getSummaryContractUpdateLogs, getTransactionKindString, AccountTransactionType, + Energy, + TransactionHash, + AccountAddress, + ContractAddress, + InitName, + Parameter, + ReceiveName, } from '../../src/index.js'; +import { expectToEqual } from '../testHelpers.js'; const chainUpdate: UpdateSummary = { type: TransactionSummaryType.UpdateTransaction, index: 0n, - energyCost: 0n, - hash: '4b4adfbe9a10a83601a1171bff0d9f916d259f744d1283726314482beeab60ee', + energyCost: Energy.create(0), + hash: TransactionHash.fromHexString( + '4b4adfbe9a10a83601a1171bff0d9f916d259f744d1283726314482beeab60ee' + ), effectiveTime: 1655118000n, payload: { updateType: UpdateType.Protocol, @@ -44,17 +54,21 @@ const chainUpdate: UpdateSummary = { const contractInit: InitContractSummary & BaseAccountTransactionSummary = { index: 0n, - energyCost: 1032n, - hash: '00205bab563b31dbd0d6cff9504a325953ac70a428ac7169f66620c40b20c431', + energyCost: Energy.create(1032), + hash: TransactionHash.fromHexString( + '00205bab563b31dbd0d6cff9504a325953ac70a428ac7169f66620c40b20c431' + ), type: TransactionSummaryType.AccountTransaction, cost: 2765192n, - sender: '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd', + sender: AccountAddress.fromBase58( + '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd' + ), transactionType: TransactionKindString.InitContract, contractInitialized: { tag: TransactionEventTag.ContractInitialized, - address: { index: 4416n, subindex: 0n }, + address: ContractAddress.create(4416), amount: 0n, - initName: 'init_cis2-receive-test', + initName: InitName.fromStringUnchecked('init_cis2-receive-test'), events: [], contractVersion: 1, ref: '627d5b8358ecf0eaa0442855d57bd84258aa1e06006cbb59ca03d31ddd5cb8b7', @@ -63,32 +77,41 @@ const contractInit: InitContractSummary & BaseAccountTransactionSummary = { const contractUpdate: UpdateContractSummary & BaseAccountTransactionSummary = { index: 0n, - energyCost: 3183n, - hash: '9f23369ed3f19cb5627f685d7193e58432e9b50e0841469b07b6d02aa7770901', + energyCost: Energy.create(3183), + hash: TransactionHash.fromHexString( + '9f23369ed3f19cb5627f685d7193e58432e9b50e0841469b07b6d02aa7770901' + ), type: TransactionSummaryType.AccountTransaction, cost: 8681698n, - sender: '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd', + sender: AccountAddress.fromBase58( + '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd' + ), transactionType: TransactionKindString.Update, events: [ { tag: TransactionEventTag.Updated, contractVersion: 1, - address: { index: 3496n, subindex: 0n }, + address: ContractAddress.create(3496), instigator: { type: 'AddressAccount', - address: '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd', + address: AccountAddress.fromBase58( + '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd' + ), }, amount: 0n, - message: - '0100006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb490000', - receiveName: 'cis2-bridgeable.transfer', + message: Parameter.fromHexString( + '0100006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb490000' + ), + receiveName: ReceiveName.fromStringUnchecked( + 'cis2-bridgeable.transfer' + ), events: [ 'ff006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb49', ], }, { tag: TransactionEventTag.Interrupted, - address: { index: 3496n, subindex: 0n }, + address: ContractAddress.create(3496), events: [ 'ff006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb49', ], @@ -96,15 +119,20 @@ const contractUpdate: UpdateContractSummary & BaseAccountTransactionSummary = { { tag: TransactionEventTag.Updated, contractVersion: 1, - address: { index: 4416n, subindex: 0n }, + address: ContractAddress.create(4416), instigator: { type: 'AddressAccount', - address: '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd', + address: AccountAddress.fromBase58( + '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd' + ), }, amount: 0n, - message: - '0100006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb490000', - receiveName: 'cis2-bridgeable.transfer', + message: Parameter.fromHexString( + '0100006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb490000' + ), + receiveName: ReceiveName.fromStringUnchecked( + 'cis2-bridgeable.transfer' + ), events: [ 'ff006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb49', ], @@ -114,7 +142,9 @@ const contractUpdate: UpdateContractSummary & BaseAccountTransactionSummary = { amount: 0n, to: { type: 'AddressAccount', - address: '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd', + address: AccountAddress.fromBase58( + '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd' + ), }, }, { @@ -122,7 +152,9 @@ const contractUpdate: UpdateContractSummary & BaseAccountTransactionSummary = { amount: 0n, to: { type: 'AddressAccount', - address: '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB', + address: AccountAddress.fromBase58( + '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB' + ), }, }, ], @@ -130,16 +162,20 @@ const contractUpdate: UpdateContractSummary & BaseAccountTransactionSummary = { const rejected: FailedTransactionSummary & BaseAccountTransactionSummary = { index: 0n, - energyCost: 4600n, - hash: '9e3eb5a2d36cb125292c553be304d943148c861f284b5d58afd215d1cfbbd8bf', + energyCost: Energy.create(4600), + hash: TransactionHash.fromHexString( + '9e3eb5a2d36cb125292c553be304d943148c861f284b5d58afd215d1cfbbd8bf' + ), type: TransactionSummaryType.AccountTransaction, cost: 12403437n, - sender: '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd', + sender: AccountAddress.fromBase58( + '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd' + ), transactionType: TransactionKindString.Failed, failedTransactionType: TransactionKindString.Update, rejectReason: { tag: RejectReasonTag.RejectedReceive, - contractAddress: { index: 3496n, subindex: 0n }, + contractAddress: ContractAddress.create(3496), receiveName: 'cis2-bridgeable.transfer', rejectReason: -5, parameter: @@ -149,48 +185,66 @@ const rejected: FailedTransactionSummary & BaseAccountTransactionSummary = { const transfer: BaseAccountTransactionSummary & TransferSummary = { index: 0n, - energyCost: 601n, - hash: 'a396ae28d1158650d52168ad108e7c5f566831fe5d0695ceab91044ba5eb6b5b', + energyCost: Energy.create(601), + hash: TransactionHash.fromHexString( + 'a396ae28d1158650d52168ad108e7c5f566831fe5d0695ceab91044ba5eb6b5b' + ), type: TransactionSummaryType.AccountTransaction, cost: 1651916n, - sender: '3v1JUB1R1JLFtcKvHqD9QFqe2NXeBF53tp69FLPHYipTjNgLrV', + sender: AccountAddress.fromBase58( + '3v1JUB1R1JLFtcKvHqD9QFqe2NXeBF53tp69FLPHYipTjNgLrV' + ), transactionType: TransactionKindString.Transfer, transfer: { tag: TransactionEventTag.Transferred, amount: 2000000000n, - to: '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', + to: AccountAddress.fromBase58( + '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe' + ), }, }; const transferToSelf: BaseAccountTransactionSummary & TransferSummary = { index: 0n, - energyCost: 601n, - hash: 'a396ae28d1158650d52168ad108e7c5f566831fe5d0695ceab91044ba5eb6b5b', + energyCost: Energy.create(601), + hash: TransactionHash.fromHexString( + 'a396ae28d1158650d52168ad108e7c5f566831fe5d0695ceab91044ba5eb6b5b' + ), type: TransactionSummaryType.AccountTransaction, cost: 1651916n, - sender: '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', + sender: AccountAddress.fromBase58( + '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe' + ), transactionType: TransactionKindString.Transfer, transfer: { tag: TransactionEventTag.Transferred, amount: 2000000000n, - to: '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', + to: AccountAddress.fromBase58( + '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe' + ), }, }; const configureDelegation: BaseAccountTransactionSummary & ConfigureDelegationSummary = { index: 0n, - energyCost: 601n, - hash: 'a396ae28d1158650d52168ad108e7c5f566831fe5d0695ceab91044ba5eb6b5b', + energyCost: Energy.create(601), + hash: TransactionHash.fromHexString( + 'a396ae28d1158650d52168ad108e7c5f566831fe5d0695ceab91044ba5eb6b5b' + ), type: TransactionSummaryType.AccountTransaction, cost: 1651916n, - sender: '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', + sender: AccountAddress.fromBase58( + '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe' + ), transactionType: TransactionKindString.ConfigureDelegation, events: [ { tag: TransactionEventTag.DelegationAdded, delegatorId: 2499, - account: '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', + account: AccountAddress.fromBase58( + '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe' + ), }, { tag: TransactionEventTag.DelegationSetDelegationTarget, @@ -199,19 +253,25 @@ const configureDelegation: BaseAccountTransactionSummary & delegateType: DelegationTargetType.Baker, bakerId: 15, }, - account: '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', + account: AccountAddress.fromBase58( + '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe' + ), }, { tag: TransactionEventTag.DelegationSetRestakeEarnings, delegatorId: 2499, restakeEarnings: true, - account: '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', + account: AccountAddress.fromBase58( + '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe' + ), }, { tag: TransactionEventTag.DelegationStakeIncreased, delegatorId: 2499, newStake: 240000000n, - account: '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', + account: AccountAddress.fromBase58( + '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe' + ), }, ], }; @@ -269,14 +329,14 @@ describe('affectedContracts', () => { test('Returns list of one contract address corresponding to contract init transaction events', () => { const contracts = affectedContracts(contractInit); - expect(contracts).toEqual([{ index: 4416n, subindex: 0n }]); + expect(contracts).toEqual([ContractAddress.create(4416)]); }); test('Returns list of unique contract addresses corresponding to contract update transaction events', () => { const contracts = affectedContracts(contractUpdate); expect(contracts).toEqual([ - { index: 3496n, subindex: 0n }, - { index: 4416n, subindex: 0n }, + ContractAddress.create(3496), + ContractAddress.create(4416), ]); }); }); @@ -289,31 +349,45 @@ describe('affectedAccounts', () => { test('Returns list of unique account addresses corresponding to transaction', () => { let accounts = affectedAccounts(contractUpdate); - expect(accounts).toEqual([ - '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd', - '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB', - ]); + expectToEqual( + accounts, + [ + '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd', + '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB', + ].map(AccountAddress.fromBase58) + ); accounts = affectedAccounts(rejected); - expect(accounts).toEqual([ - '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd', + expectToEqual(accounts, [ + AccountAddress.fromBase58( + '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd' + ), ]); accounts = affectedAccounts(transfer); - expect(accounts).toEqual([ - '3v1JUB1R1JLFtcKvHqD9QFqe2NXeBF53tp69FLPHYipTjNgLrV', - '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', - ]); + expectToEqual( + accounts, + [ + '3v1JUB1R1JLFtcKvHqD9QFqe2NXeBF53tp69FLPHYipTjNgLrV', + '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', + ].map(AccountAddress.fromBase58) + ); accounts = affectedAccounts(transferToSelf); - expect(accounts).toEqual([ - '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', - ]); + expectToEqual( + accounts, + ['4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe'].map( + AccountAddress.fromBase58 + ) + ); accounts = affectedAccounts(configureDelegation); - expect(accounts).toEqual([ - '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe', - ]); + expectToEqual( + accounts, + ['4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe'].map( + AccountAddress.fromBase58 + ) + ); }); }); @@ -330,19 +404,19 @@ describe('getSummaryContractUpdateLogs', () => { const logs = getSummaryContractUpdateLogs(contractUpdate); expect(logs).toEqual([ { - address: { index: 3496n, subindex: 0n }, + address: ContractAddress.create(3496), events: [ 'ff006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb49', ], }, { - address: { index: 3496n, subindex: 0n }, + address: ContractAddress.create(3496), events: [ 'ff006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb49', ], }, { - address: { index: 4416n, subindex: 0n }, + address: ContractAddress.create(4416), events: [ 'ff006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb49', ], diff --git a/packages/common/test/util.test.ts b/packages/common/test/util.test.ts index 01ae587df..c65b0fc7d 100644 --- a/packages/common/test/util.test.ts +++ b/packages/common/test/util.test.ts @@ -92,5 +92,5 @@ test('Embedded schema is the same as a seperate schema file', () => { const seperateSchema = readFileSync('test/resources/icecream-schema.bin'); const embeddedSchema = wasmToSchema(wasmModule); - expect(seperateSchema).toEqual(embeddedSchema); + expect(new Uint8Array(seperateSchema)).toEqual(embeddedSchema); }); diff --git a/packages/common/test/web3IdHelpers.test.ts b/packages/common/test/web3IdHelpers.test.ts index b9cd19ee4..b684b3f88 100644 --- a/packages/common/test/web3IdHelpers.test.ts +++ b/packages/common/test/web3IdHelpers.test.ts @@ -8,6 +8,7 @@ import { isStringAttributeInRange, timestampToDate, verifyWeb3IdCredentialSignature, + ContractAddress, } from '../src/index.js'; const globalContext = JSON.parse( @@ -33,7 +34,7 @@ const holder = '32c0b24855060114c7b781bc94fcb089edc255f16e78ece9b597bf0c6880fa98'; const issuerPublicKey = '2DC9C80EBF73F6EE44F6BD8C067C1FCE660C9B78779A5CD4674A56B59C3474B2'; -const issuerContract = { index: 5463n, subindex: 0n }; +const issuerContract = ContractAddress.create(5463); test('verifyWeb3IdCredentialSignature', async () => { expect( @@ -67,7 +68,7 @@ test('verifyWeb3IdCredentialSignature can reject due to incorrect signature', as }); test('verifyWeb3IdCredentialSignature can reject due to incorrect issuer contract', async () => { - const incorrectIssuerContract = { index: 4463n, subindex: 0n }; + const incorrectIssuerContract = ContractAddress.create(4463); expect( verifyWeb3IdCredentialSignature({ globalContext, @@ -121,7 +122,7 @@ test('verifyWeb3IdCredentialSignature with timestamps', async () => { '666b4811c26b36357186b6c286261930d12a8772776d70c485a9b16059881824'; const issuerPublicKey = '00ee7c443e604fbe6defbbc08ee0bf25e76656037fc189c41e631ac3a0ab136d'; - const issuerContract = { index: 6105n, subindex: 0n }; + const issuerContract = ContractAddress.create(6105); expect( verifyWeb3IdCredentialSignature({ diff --git a/packages/common/test/web3Proofs.test.ts b/packages/common/test/web3Proofs.test.ts index 02453b3fa..d8be212e6 100644 --- a/packages/common/test/web3Proofs.test.ts +++ b/packages/common/test/web3Proofs.test.ts @@ -1,6 +1,7 @@ import { AttributeKeyString, ConcordiumHdWallet, + ContractAddress, createAccountDID, createWeb3IdDID, dateToTimestampAttribute, @@ -36,16 +37,13 @@ test('Generate V2 statement', () => { const builder = new Web3StatementBuilder(); const statement = builder .addForVerifiableCredentials( - [ - { index: 2101n, subindex: 0n }, - { index: 1337n, subindex: 42n }, - ], + [ContractAddress.create(2101), ContractAddress.create(1337, 42)], (b) => b .addRange('b', 80n, 1237n) .addMembership('c', ['aa', 'ff', 'zz']) ) - .addForVerifiableCredentials([{ index: 1338n, subindex: 0n }], (b) => + .addForVerifiableCredentials([ContractAddress.create(1338)], (b) => b .addRange('a', 80n, 1237n) .addNonMembership('d', ['aa', 'ff', 'zz']) @@ -151,7 +149,7 @@ test('create Web3Id proof with Web3Id Credentials', () => { const wallet = ConcordiumHdWallet.fromHex(TEST_SEED_1, 'Testnet'); const publicKey = wallet - .getVerifiableCredentialPublicKey({ index: 1n, subindex: 0n }, 1) + .getVerifiableCredentialPublicKey(ContractAddress.create(1), 1) .toString('hex'); const values: Record = { @@ -181,10 +179,7 @@ test('create Web3Id proof with Web3Id Credentials', () => { { type: 'web3Issuer', signer: wallet - .getVerifiableCredentialSigningKey( - { index: 1n, subindex: 0n }, - 1 - ) + .getVerifiableCredentialSigningKey(ContractAddress.create(1), 1) .toString('hex'), values, randomness, @@ -286,7 +281,7 @@ test('Generate statement with timestamp', () => { const statement = builder .addForVerifiableCredentials( - [{ index: 0n, subindex: 0n }], + [ContractAddress.create(0)], (b) => b.addRange('graduationDate', lower, upper), schemaWithTimeStamp ) @@ -307,7 +302,7 @@ test('Generate statement with timestamp fails if not timestamp attribute', () => expect(() => builder.addForVerifiableCredentials( - [{ index: 0n, subindex: 0n }], + [ContractAddress.create(0)], (b) => b // Use degreeName, which is a string property, not timestamp diff --git a/packages/nodejs/test/CIS2Contract.test.ts b/packages/nodejs/test/CIS2Contract.test.ts index beed28a65..c20d2834f 100644 --- a/packages/nodejs/test/CIS2Contract.test.ts +++ b/packages/nodejs/test/CIS2Contract.test.ts @@ -1,8 +1,12 @@ import { AccountAddress, AccountTransactionType, + BlockHash, ContractAddress, + Energy, EntrypointName, + Parameter, + ReceiveName, TransactionEventTag, } from '@concordium/common-sdk'; import { getNodeClientV2 as getNodeClient } from './testHelpers.js'; @@ -12,8 +16,9 @@ import { serializeTypeValue } from '@concordium/common-sdk/schema'; const CIS2_FT_ADDRESS = ContractAddress.create(3496); const CIS2_NFT_ADDRESS = ContractAddress.create(1696); -const TEST_BLOCK = - '3e9d90325c61ab190065f3c90364beeb925833319de68d982ec6da7762e8357b'; +const TEST_BLOCK = BlockHash.fromHexString( + '3e9d90325c61ab190065f3c90364beeb925833319de68d982ec6da7762e8357b' +); const TEST_ACCOUNT = AccountAddress.fromBase58( '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd' ); @@ -109,13 +114,13 @@ test('dryRun.transfer', async () => { }, TEST_BLOCK ); - expect(result.usedEnergy).toEqual(2803n); + expect(result.usedEnergy.value).toBe(2803n); // Results in 1 transfer event expect( result.tag === 'success' && result.events[0].tag === TransactionEventTag.Updated && result.events[0].events.length - ).toEqual(1); + ).toBe(1); const resultMulti = await cis2.dryRun.transfer( TEST_ACCOUNT, @@ -140,13 +145,13 @@ test('dryRun.transfer', async () => { TEST_BLOCK ); - expect(resultMulti.usedEnergy).toEqual(3278n); + expect(resultMulti.usedEnergy.value).toBe(3278n); // Results in 2 transfer events expect( resultMulti.tag === 'success' && resultMulti.events[0].tag === TransactionEventTag.Updated && resultMulti.events[0].events.length - ).toEqual(2); + ).toBe(2); const resultContractReceiver = await cis2.dryRun.transfer( TEST_ACCOUNT, @@ -159,16 +164,18 @@ test('dryRun.transfer', async () => { }, tokenAmount: 0n, }, - 'a03ca5112f2bf38bbb4f4d524432ff3a060226d823a3a868aa23b7d0d628e112' + BlockHash.fromHexString( + 'a03ca5112f2bf38bbb4f4d524432ff3a060226d823a3a868aa23b7d0d628e112' + ) ); - expect(resultContractReceiver.tag).toEqual('success'); + expect(resultContractReceiver.tag).toBe('success'); }); describe('createTransfer', () => { test('single update', async () => { const cis2 = await getCIS2Single(); const { type, parameter, payload } = cis2.createTransfer( - { energy: 1000000n }, + { energy: Energy.create(1000000) }, { tokenId: '', to: AccountAddress.fromBase58( @@ -190,7 +197,7 @@ describe('createTransfer', () => { { token_id: '', amount: '100', - from: { Account: [TEST_ACCOUNT] }, + from: { Account: [AccountAddress.toBase58(TEST_ACCOUNT)] }, to: { Account: [ '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB', @@ -202,34 +209,48 @@ describe('createTransfer', () => { // Checks that payload contains the expected values expect(payload.amount.microCcdAmount).toEqual(0n); - expect(payload.address).toEqual({ index: 3496n, subindex: 0n }); - expect(payload.message.toString('hex')).toEqual(expectedParameterHex); - expect(payload.receiveName).toEqual('cis2-bridgeable.transfer'); - expect(payload.maxContractExecutionEnergy).toEqual(1000000n); + expect( + ContractAddress.equals( + payload.address, + ContractAddress.create(3496) + ) + ).toBeTruthy(); + expect(Parameter.toHexString(payload.message)).toEqual( + expectedParameterHex + ); + expect(payload.receiveName).toEqual( + ReceiveName.fromStringUnchecked('cis2-bridgeable.transfer') + ); + expect(payload.maxContractExecutionEnergy.value).toEqual(1000000n); }); test('multiple transfers', async () => { const cis2 = await getCIS2Single(); - const { parameter, schema } = cis2.createTransfer({ energy: 10000n }, [ - { - tokenId: '', - to: AccountAddress.fromBase58( - '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB' - ), - from: TEST_ACCOUNT, - tokenAmount: 100n, - }, - { - tokenId: '', - from: TEST_ACCOUNT, - to: { - address: ContractAddress.create(4416), - hookName: - EntrypointName.fromStringUnchecked('onReceivingCIS2'), + const { parameter, schema } = cis2.createTransfer( + { energy: Energy.create(10000) }, + [ + { + tokenId: '', + to: AccountAddress.fromBase58( + '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB' + ), + from: TEST_ACCOUNT, + tokenAmount: 100n, }, - tokenAmount: 0n, - }, - ]); + { + tokenId: '', + from: TEST_ACCOUNT, + to: { + address: ContractAddress.create(4416), + hookName: + EntrypointName.fromStringUnchecked( + 'onReceivingCIS2' + ), + }, + tokenAmount: 0n, + }, + ] + ); const expectedParameterHex = '0200006400c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f0087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb490000000000c8d4bb7106a96bfa6f069438270bf9748049c24798b13b08f88fc2f46afb435f01401100000000000000000000000000000f006f6e526563656976696e67434953320000'; // Parameter is formatted and serialized as expected @@ -238,7 +259,7 @@ describe('createTransfer', () => { { token_id: '', amount: '100', - from: { Account: [TEST_ACCOUNT] }, + from: { Account: [AccountAddress.toBase58(TEST_ACCOUNT)] }, to: { Account: [ '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB', @@ -249,7 +270,7 @@ describe('createTransfer', () => { { token_id: '', amount: '0', - from: { Account: [TEST_ACCOUNT] }, + from: { Account: [AccountAddress.toBase58(TEST_ACCOUNT)] }, to: { Contract: [{ index: 4416, subindex: 0 }, 'onReceivingCIS2'], }, @@ -276,7 +297,7 @@ test('dryRun.updateOperator', async () => { }, TEST_BLOCK ); - expect(result.usedEnergy).toEqual(2735n); + expect(result.usedEnergy.value).toEqual(2735n); // Results in 1 transfer event expect( result.tag === 'success' && @@ -301,7 +322,7 @@ test('dryRun.updateOperator', async () => { TEST_BLOCK ); - expect(resultMulti.usedEnergy).toEqual(2960n); + expect(resultMulti.usedEnergy.value).toEqual(2960n); // Results in 2 transfer events expect( resultMulti.tag === 'success' && @@ -314,7 +335,7 @@ describe('createUpdateOperator', () => { test('single update', async () => { const cis2 = await getCIS2Single(); const { type, parameter, payload } = cis2.createUpdateOperator( - { energy: 1000000n }, + { energy: Energy.create(1000000) }, { type: 'add', address: AccountAddress.fromBase58( @@ -343,26 +364,33 @@ describe('createUpdateOperator', () => { // Checks that payload contains the expected values expect(payload.amount.microCcdAmount).toEqual(0n); - expect(payload.address).toEqual({ index: 3496n, subindex: 0n }); - expect(payload.message.toString('hex')).toEqual(expectedParameterHex); - expect(payload.receiveName).toEqual('cis2-bridgeable.updateOperator'); - expect(payload.maxContractExecutionEnergy).toEqual(1000000n); + expect(payload.address).toEqual(ContractAddress.create(3496)); + expect(Parameter.toHexString(payload.message)).toEqual( + expectedParameterHex + ); + expect(payload.receiveName.value).toEqual( + 'cis2-bridgeable.updateOperator' + ); + expect(payload.maxContractExecutionEnergy.value).toEqual(1000000n); }); test('multiple updates', async () => { const cis2 = await getCIS2Single(); - const { parameter } = cis2.createUpdateOperator({ energy: 1000000n }, [ - { - type: 'add', - address: AccountAddress.fromBase58( - '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB' - ), - }, - { - type: 'remove', - address: ContractAddress.create(3494), - }, - ]); + const { parameter } = cis2.createUpdateOperator( + { energy: Energy.create(1000000) }, + [ + { + type: 'add', + address: AccountAddress.fromBase58( + '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB' + ), + }, + { + type: 'remove', + address: ContractAddress.create(3494), + }, + ] + ); const expectedParameterHex = '0200010087e3bec61b8db2fb7389b57d2be4f7dd95d1088dfeb6ef7352c13d2b2d27bb490001a60d0000000000000000000000000000'; // Parameter is formatted and serialized as expected diff --git a/packages/nodejs/test/CIS4Contract.test.ts b/packages/nodejs/test/CIS4Contract.test.ts index 9344ee821..495bf35bd 100644 --- a/packages/nodejs/test/CIS4Contract.test.ts +++ b/packages/nodejs/test/CIS4Contract.test.ts @@ -3,6 +3,7 @@ import { AccountAddress, Timestamp, Energy, + BlockHash, } from '@concordium/common-sdk'; import { serializeTypeValue } from '@concordium/common-sdk/schema'; import { CIS4, CIS4Contract, Web3IdSigner } from '@concordium/common-sdk/cis4'; @@ -36,8 +37,9 @@ const NEW_REVOKER_2_KEYPAIR = { }; const WEB3ID_ADDRESS_REVOKE = ContractAddress.create(5587); -const TEST_BLOCK = - 'bf956ef81bb6a22eda754d490bdb7a3085318b3a1fe9370f83f86649a5f7cb60'; +const TEST_BLOCK = BlockHash.fromHexString( + 'bf956ef81bb6a22eda754d490bdb7a3085318b3a1fe9370f83f86649a5f7cb60' +); const getCIS4 = () => CIS4Contract.create(getNodeClient(), WEB3ID_ADDRESS_REVOKE); @@ -60,7 +62,7 @@ describe('credentialEntry', () => { new Date('2023-08-01T13:47:02.260Z') ), validUntil: Timestamp.fromDate( - new Date('2023-08-01T13:47:02.260Z') + new Date('2025-08-01T13:47:02.260Z') ), metadataUrl: { url: '' }, }, @@ -211,6 +213,7 @@ describe('registerRevocationKeys', () => { const res = await cis4.dryRun.registerRevocationKeys( ISSUER_ACCOUNT, NEW_REVOKER_1_KEYPAIR.pub, + undefined, TEST_BLOCK ); expect(res.tag).toBe('success'); @@ -264,6 +267,7 @@ describe('removeRevocationKeys', () => { const res = await cis4.dryRun.removeRevocationKeys( ISSUER_ACCOUNT, REVOKER_KEYPAIR.pub, + undefined, TEST_BLOCK ); expect(res.tag).toBe('success'); diff --git a/packages/nodejs/test/clientV2.test.ts b/packages/nodejs/test/clientV2.test.ts index ddf2bcef8..ba18f4bee 100644 --- a/packages/nodejs/test/clientV2.test.ts +++ b/packages/nodejs/test/clientV2.test.ts @@ -12,12 +12,14 @@ import { createCredentialDeploymentTransaction, serializeAccountTransaction, streamToList, + BlockHash, } from '@concordium/common-sdk'; import { getModuleBuffer, getIdentityInput, getNodeClientV2, getNodeClientWeb, + expectToEqual, } from './testHelpers.js'; import * as ed from '@noble/ed25519'; import * as expected from './resources/expectedJsons.js'; @@ -50,8 +52,9 @@ const testAccBaker = v1.AccountAddress.fromBase58( const testAccDeleg = v1.AccountAddress.fromBase58( '3bFo43GiPnkk5MmaSdsRVboaX2DNSKaRkLseQbyB3WPW1osPwh' ); -const testBlockHash = - 'fe88ff35454079c3df11d8ae13d5777babd61f28be58494efe51b6593e30716e'; +const testBlockHash = v1.BlockHash.fromHexString( + 'fe88ff35454079c3df11d8ae13d5777babd61f28be58494efe51b6593e30716e' +); // Retrieves the account info for the given account in the GRPCv2 type format. function getAccountInfoV2( @@ -87,7 +90,7 @@ test.each([clientV2, clientWeb])( test.each([clientV2, clientWeb])('nextAccountNonce', async (client) => { const nan = await client.getNextAccountNonce(testAccount); - expect(nan.nonce).toBeGreaterThanOrEqual(19n); + expect(nan.nonce.value).toBeGreaterThanOrEqual(19n); expect(nan.allFinal).toBeDefined(); }); @@ -97,21 +100,6 @@ test.each([clientV2, clientWeb])('getAccountInfo', async (client) => { expect(v2.AccountInfo.toJson(accountInfo)).toEqual(expected.accountInfo); }); -test.each([clientV2, clientWeb])( - 'getAccountInfo: Invalid hash throws error', - async (client) => { - const invalidBlockHash = '1010101010'; - await expect( - client.getAccountInfo(testAccount, invalidBlockHash) - ).rejects.toEqual( - new Error( - 'The input was not a valid hash, must be 32 bytes: ' + - invalidBlockHash - ) - ); - } -); - test.each([clientV2, clientWeb])('getAccountInfo for baker', async (client) => { const accInfo = await getAccountInfoV2(client, testAccBaker); const accountIndexInfo = await getAccountInfoV2(client, 5n); @@ -152,7 +140,7 @@ test.each([clientV2, clientWeb])( testBlockHash ); - expect(accInfo).toEqual(credIdInfo); + expectToEqual(accInfo, credIdInfo); } ); @@ -164,10 +152,10 @@ test.each([clientV2, clientWeb])( const baker = await client.getAccountInfo(testAccBaker, testBlockHash); const deleg = await client.getAccountInfo(testAccDeleg, testBlockHash); - expect(regular).toEqual(expected.regularAccountInfo); - expect(credId).toEqual(expected.credIdAccountInfo); - expect(baker).toEqual(expected.bakerAccountInfo); - expect(deleg).toEqual(expected.delegatorAccountInfo); + expectToEqual(regular, expected.regularAccountInfo); + expectToEqual(credId, expected.credIdAccountInfo); + expectToEqual(baker, expected.bakerAccountInfo); + expectToEqual(deleg, expected.delegatorAccountInfo); } ); @@ -185,8 +173,9 @@ test.each([clientV2, clientWeb])( test.each([clientV2, clientWeb])( 'getChainParameters corresponds to GetBlockSummary subset on protocol level < 4', async (client) => { - const oldBlockHash = - 'ed2507c4d05108038741e87757ab1c3acdeeb3327027cd2972666807c9c4a20d'; + const oldBlockHash = v1.BlockHash.fromHexString( + 'ed2507c4d05108038741e87757ab1c3acdeeb3327027cd2972666807c9c4a20d' + ); const oldChainParameters = await client.getBlockChainParameters( oldBlockHash ); @@ -216,8 +205,9 @@ test.each([clientV2, clientWeb])( test.each([clientV2, clientWeb])( 'getPoolInfo corresponds to getPoolStatus with bakerId (with pending change)', async (client) => { - const changeHash = - '2aa7c4a54ad403a9f9b48de2469e5f13a64c95f2cf7a8e72c0f9f7ae0718f642'; + const changeHash = v1.BlockHash.fromHexString( + '2aa7c4a54ad403a9f9b48de2469e5f13a64c95f2cf7a8e72c0f9f7ae0718f642' + ); const changedAccount = 1879n; const poolStatus = await client.getPoolInfo(changedAccount, changeHash); @@ -229,8 +219,9 @@ test.each([clientV2, clientWeb])( test.each([clientV2, clientWeb])( 'getBlockItemStatus on chain update', async (client) => { - const transactionHash = - '3de823b876d05cdd33a311a0f84124079f5f677afb2534c4943f830593edc650'; + const transactionHash = v1.TransactionHash.fromHexString( + '3de823b876d05cdd33a311a0f84124079f5f677afb2534c4943f830593edc650' + ); const blockItemStatus = await client.getBlockItemStatus( transactionHash ); @@ -242,8 +233,9 @@ test.each([clientV2, clientWeb])( test.each([clientV2, clientWeb])( 'getBlockItemStatus on simple transfer', async (client) => { - const transactionHash = - '502332239efc0407eebef5c73c390080e5d7e1b127ff29f786a62b3c9ab6cfe7'; + const transactionHash = v1.TransactionHash.fromHexString( + '502332239efc0407eebef5c73c390080e5d7e1b127ff29f786a62b3c9ab6cfe7' + ); const blockItemStatus = await client.getBlockItemStatus( transactionHash ); @@ -253,10 +245,7 @@ test.each([clientV2, clientWeb])( ); test.each([clientV2, clientWeb])('getInstanceInfo', async (client) => { - const contractAddress = { - index: 0n, - subindex: 0n, - }; + const contractAddress = v1.ContractAddress.create(0, 0); const instanceInfo = await client.getInstanceInfo( contractAddress, testBlockHash @@ -269,14 +258,11 @@ test.each([clientV2, clientWeb])('Failed invoke contract', async (client) => { const result = await client.invokeContract( { invoker: testAccount, - contract: { - index: 6n, - subindex: 0n, - }, - method: 'PiggyBank.smash', + contract: v1.ContractAddress.create(6), + method: v1.ReceiveName.fromStringUnchecked('PiggyBank.smash'), amount: new v1.CcdAmount(0n), parameter: undefined, - energy: 30000n, + energy: v1.Energy.create(30000), }, testBlockHash ); @@ -285,7 +271,7 @@ test.each([clientV2, clientWeb])('Failed invoke contract', async (client) => { throw new Error('Expected invoke to be fail'); } - expect(result.usedEnergy).toBe(340n); + expect(result.usedEnergy.value).toBe(340n); expect(result.reason.tag).toBe(v1.RejectReasonTag.RejectedReceive); }); @@ -295,14 +281,11 @@ test.each([clientV2, clientWeb])( const result = await client.invokeContract( { invoker: testAccount, - contract: { - index: 6n, - subindex: 0n, - }, - method: 'PiggyBank.insert', + contract: v1.ContractAddress.create(6), + method: v1.ReceiveName.fromStringUnchecked('PiggyBank.insert'), amount: new v1.CcdAmount(1n), parameter: undefined, - energy: 30000n, + energy: v1.Energy.create(30000), }, testBlockHash ); @@ -316,14 +299,11 @@ test.each([clientV2, clientWeb])( async (client) => { const context = { invoker: testAccount, - contract: { - index: 81n, - subindex: 0n, - }, - method: 'PiggyBank.view', + contract: v1.ContractAddress.create(81), + method: v1.ReceiveName.fromStringUnchecked('PiggyBank.view'), amount: new v1.CcdAmount(0n), parameter: undefined, - energy: 30000n, + energy: v1.Energy.create(30000), }; const result = await client.invokeContract(context, testBlockHash); @@ -347,12 +327,15 @@ test.each([clientV2, clientWeb])('getModuleSource', async (client) => { ); expect(versionedModuleSource.version).toEqual(0); - expect(localModuleHex).toEqual(versionedModuleSource.source); + expect(new Uint8Array(localModuleHex)).toEqual( + new Uint8Array(versionedModuleSource.source) + ); }); test.each([clientV2, clientWeb])('getConsensusStatus', async (client) => { - const genesisBlock = - '4221332d34e1694168c2a0c0b3fd0f273809612cb13d000d5c2e00e85f50f796'; + const genesisBlock = v1.BlockHash.fromHexString( + '4221332d34e1694168c2a0c0b3fd0f273809612cb13d000d5c2e00e85f50f796' + ); const ci = await client.getConsensusStatus(); @@ -445,9 +428,9 @@ test.each([clientV2, clientWeb])('transactionHash', async (client) => { // Put together sendBlockItemRequest const header: v2.AccountTransactionHeader = { - sender: { value: transaction.header.sender.decodedAddress }, - sequenceNumber: { value: transaction.header.nonce }, - energyAmount: { value: energyCost }, + sender: v1.AccountAddress.toProto(transaction.header.sender), + sequenceNumber: v1.SequenceNumber.toProto(transaction.header.nonce), + energyAmount: v1.Energy.toProto(energyCost), expiry: { value: transaction.header.expiry.expiryEpochSeconds }, }; const accountTransaction: v2.PreAccountTransaction = { @@ -554,10 +537,7 @@ test.each([clientV2, clientWeb])('getAncestors', async (client) => { }); test.each([clientV2, clientWeb])('getInstanceState', async (client) => { - const contract = { - index: 602n, - subindex: 0n, - }; + const contract = v1.ContractAddress.create(602); const instanceStateIter = client.getInstanceState(contract, testBlockHash); const instanceStateList = await streamToList(instanceStateIter); @@ -567,10 +547,7 @@ test.each([clientV2, clientWeb])('getInstanceState', async (client) => { test.each([clientV2, clientWeb])('instanceStateLookup', async (client) => { const key = '0000000000000000'; const expectedValue = '0800000000000000'; - const contract = { - index: 601n, - subindex: 0n, - }; + const contract = v1.ContractAddress.create(601); const value = await client.instanceStateLookup( contract, key, @@ -611,8 +588,9 @@ test.each([clientV2, clientWeb])( height: 100n, restrict: true, }; - const expectedBlock = - '956c3bc5c9d10449e13686a4cc69e8bc7dee450608866242075a6ce37331187c'; + const expectedBlock = v1.BlockHash.fromHexString( + '956c3bc5c9d10449e13686a4cc69e8bc7dee450608866242075a6ce37331187c' + ); const blocks = await client.getBlocksAtHeight(request); expect(blocks[0]).toEqual(expectedBlock); @@ -709,8 +687,9 @@ test.each([clientV2, clientWeb])( test.each([clientV2, clientWeb])( 'getBlockTransactionEvents', async (client) => { - const blockHash = - '8f3acabb19ef769db4d13ada858a305cc1a3d64adeb78fcbf3bb9f7583de6362'; + const blockHash = v1.BlockHash.fromHexString( + '8f3acabb19ef769db4d13ada858a305cc1a3d64adeb78fcbf3bb9f7583de6362' + ); const transactionEvents = client.getBlockTransactionEvents(blockHash); const transactionEventList = await streamToList(transactionEvents); @@ -721,8 +700,9 @@ test.each([clientV2, clientWeb])( test.each([clientV2, clientWeb])( 'getBlockTransactionEvents', async (client) => { - const blockHash = - '8f3acabb19ef769db4d13ada858a305cc1a3d64adeb78fcbf3bb9f7583de6362'; + const blockHash = v1.BlockHash.fromHexString( + '8f3acabb19ef769db4d13ada858a305cc1a3d64adeb78fcbf3bb9f7583de6362' + ); const transactionEvents = client.getBlockTransactionEvents(blockHash); const transactionEventList = await streamToList(transactionEvents); @@ -749,8 +729,9 @@ test.each([clientV2, clientWeb])('getBlockSpecialEvents', async (client) => { }); test.each([clientV2, clientWeb])('getBlockPendingUpdates', async (client) => { - const pendingUpdateBlock = - '39122a9c720cae643b999d93dd7bf09bcf50e99bb716767dd35c39690390db54'; + const pendingUpdateBlock = v1.BlockHash.fromHexString( + '39122a9c720cae643b999d93dd7bf09bcf50e99bb716767dd35c39690390db54' + ); const pendingUpdateStream = client.getBlockPendingUpdates(pendingUpdateBlock); const pendingUpdateList = await streamToList(pendingUpdateStream); @@ -770,20 +751,23 @@ test.each([clientV2, clientWeb])( ); test.each([clientV2, clientWeb])('getEmbeddedSchema', async (client) => { - const contract = { index: 4422n, subindex: 0n }; + const contract = v1.ContractAddress.create(4422); const moduleRef = new v1.ModuleReference( '44434352ddba724930d6b1b09cd58bd1fba6ad9714cf519566d5fe72d80da0d1' ); const schema = await client.getEmbeddedSchema(moduleRef); - const context = { contract, method: 'weather.get' }; + const context = { + contract, + method: v1.ReceiveName.fromStringUnchecked('weather.get'), + }; const invoked = await client.invokeContract(context); if (invoked.tag === 'success' && invoked.returnValue) { - const rawReturnValue = Buffer.from(invoked.returnValue, 'hex'); + const rawReturnValue = invoked.returnValue; const returnValue = deserializeReceiveReturnValue( - rawReturnValue, + v1.ReturnValue.toBuffer(rawReturnValue), schema, 'weather', 'get' @@ -795,7 +779,7 @@ test.each([clientV2, clientWeb])('getEmbeddedSchema', async (client) => { }); // For tests that take a long time to run, is skipped by default -describe.skip('Long run-time test suite', () => { +describe('Long run-time test suite', () => { const longTestTime = 45000; // Sometimes fails as there is no guarantee that a new block comes fast enough. @@ -835,15 +819,21 @@ test.each([clientV2, clientWeb])('getFinalizedBlocksFrom', async (client) => { const expectedValues = [ { height: 123n, - hash: 'd2f69ff78b898c4eb0863bcbc179764b3ed20ed142e93eb3ed0cfc730c77f4ca', + hash: v1.BlockHash.fromHexString( + 'd2f69ff78b898c4eb0863bcbc179764b3ed20ed142e93eb3ed0cfc730c77f4ca' + ), }, { height: 124n, - hash: 'fc86847a2482d5eb36028fe4a4702d1cd52d6d6f953d5effe4855acc974dfc64', + hash: v1.BlockHash.fromHexString( + 'fc86847a2482d5eb36028fe4a4702d1cd52d6d6f953d5effe4855acc974dfc64' + ), }, { height: 125n, - hash: 'bc5e6aadad1bd5d107a8a02e7df5532f6c758ec456f709cfba1f402c408e7256', + hash: v1.BlockHash.fromHexString( + 'bc5e6aadad1bd5d107a8a02e7df5532f6c758ec456f709cfba1f402c408e7256' + ), }, ]; @@ -852,7 +842,7 @@ test.each([clientV2, clientWeb])('getFinalizedBlocksFrom', async (client) => { expect(bis.length).toBe(3); bis.forEach((bi, i) => { expect(bi.height).toBe(expectedValues[i].height); - expect(bi.hash).toBe(expectedValues[i].hash); + expect(bi.hash).toEqual(expectedValues[i].hash); }); }); @@ -873,7 +863,10 @@ describe('findEarliestFinalized', () => { if (accounts.length > genesisAccounts.length) { return accounts.filter( - (a) => !genesisAccounts.includes(a) + (a) => + !genesisAccounts.some( + v1.AccountAddress.equals.bind(undefined, a) + ) )[0]; } }, @@ -881,23 +874,36 @@ describe('findEarliestFinalized', () => { 10000n ); - expect(firstAccount).toBe( - '3sPayiQEQHrJUpwYUAnYCLWUTkk3JvEW5x6Vn6mD4raBgPAuSp' - ); + if (firstAccount === undefined) { + throw new Error('Expected firstAccount to be defined'); + } + expect( + v1.AccountAddress.equals( + firstAccount, + v1.AccountAddress.fromBase58( + '3sPayiQEQHrJUpwYUAnYCLWUTkk3JvEW5x6Vn6mD4raBgPAuSp' + ) + ) + ).toBeTruthy(); } ); test.each([clientV2, clientWeb])( 'Works on single block range', async (client) => { - const firstAccount = await client.findEarliestFinalized( + const blockHash = await client.findEarliestFinalized( async (bi) => bi.hash, 10000n, 10000n ); + if (blockHash === undefined) { + throw new Error('Expected blockHash to be defined'); + } - expect(firstAccount).toBe( - 'e4f7f5512e55183f56efe31c1a9da6e5c7f93f24d5b746180e3b5076e54811c1' + expect(blockHash).toEqual( + BlockHash.fromHexString( + 'e4f7f5512e55183f56efe31c1a9da6e5c7f93f24d5b746180e3b5076e54811c1' + ) ); } ); @@ -905,7 +911,7 @@ describe('findEarliestFinalized', () => { test.each([clientV2, clientWeb])('findInstanceCreation', async (client) => { const blockFirstContract = await client.findInstanceCreation( - { index: 0n, subindex: 0n }, + v1.ContractAddress.create(0), 0n, 10000n ); diff --git a/packages/nodejs/test/events.test.ts b/packages/nodejs/test/events.test.ts index a038fbe49..db32c5b4b 100644 --- a/packages/nodejs/test/events.test.ts +++ b/packages/nodejs/test/events.test.ts @@ -1,23 +1,28 @@ import * as expected from './resources/expectedJsons.js'; -import { streamToList } from '@concordium/common-sdk'; -import { getNodeClientV2 as getNodeClient } from './testHelpers.js'; +import { streamToList, BlockHash } from '@concordium/common-sdk'; +import { + expectToEqual, + getNodeClientV2 as getNodeClient, +} from './testHelpers.js'; const client = getNodeClient(); // AccountCreated test('accountCreated', async () => { - const blockHash = - '67fd6360f39ea6d815133878e64070c578a66012b3eaa757cd1dba8a993079ea'; + const blockHash = BlockHash.fromHexString( + '67fd6360f39ea6d815133878e64070c578a66012b3eaa757cd1dba8a993079ea' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); - expect(events[0]).toEqual(expected.accountCreationEvent); + expectToEqual(events[0], expected.accountCreationEvent); }); // EncryptedAmountsRemoved, AmountAddedByDecryption test('transferToPublic', async () => { - const blockHash = - 'e59ba7559e2de14e1bd4c05ddbfca808dd5b870cd89eec3942ae29f842906262'; + const blockHash = BlockHash.fromHexString( + 'e59ba7559e2de14e1bd4c05ddbfca808dd5b870cd89eec3942ae29f842906262' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -27,7 +32,7 @@ test('transferToPublic', async () => { event.transactionType === 'transferToPublic' ) { const transferToPublicEvent = [event.removed, event.added]; - expect(transferToPublicEvent).toEqual(expected.transferToPublicEvent); + expectToEqual(transferToPublicEvent, expected.transferToPublicEvent); } else { throw Error('Wrong event.'); } @@ -37,8 +42,9 @@ test('transferToPublic', async () => { // BakerSetMetadataURL, BakerSetOpenStatus, BakerSetRestakeEarnings // BakerSetTransactionFeeCommission test('configureBaker: Add baker', async () => { - const blockHash = - '04d24b3d44e4ec4681c279424bd276215809a6af64e57fd20cd907a08d998f09'; + const blockHash = BlockHash.fromHexString( + '04d24b3d44e4ec4681c279424bd276215809a6af64e57fd20cd907a08d998f09' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -47,7 +53,7 @@ test('configureBaker: Add baker', async () => { event.type === 'accountTransaction' && event.transactionType === 'configureBaker' ) { - expect(event.events).toEqual(expected.configureBaker); + expectToEqual(event.events, expected.configureBaker); } else { throw Error('Wrong event.'); } @@ -55,8 +61,9 @@ test('configureBaker: Add baker', async () => { // BakerRemoved test('configureBaker: Remove baker', async () => { - const blockHash = - '2aa7c4a54ad403a9f9b48de2469e5f13a64c95f2cf7a8e72c0f9f7ae0718f642'; + const blockHash = BlockHash.fromHexString( + '2aa7c4a54ad403a9f9b48de2469e5f13a64c95f2cf7a8e72c0f9f7ae0718f642' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -65,7 +72,7 @@ test('configureBaker: Remove baker', async () => { event.type === 'accountTransaction' && event.transactionType === 'configureBaker' ) { - expect(event.events[0]).toEqual(expected.bakerRemoved); + expectToEqual(event.events[0], expected.bakerRemoved); } else { throw Error('Wrong event.'); } @@ -74,8 +81,9 @@ test('configureBaker: Remove baker', async () => { // DelegationAdded, DelegationSetDelegationTarget, DelegationSetRestakeEarnings // DelegationStakeIncreased, test('configureDelegation', async () => { - const blockHash = - '9cf7f3ba97e027f08bc3dc779e6eb4aadaecee0899a532224846196f646921f3'; + const blockHash = BlockHash.fromHexString( + '9cf7f3ba97e027f08bc3dc779e6eb4aadaecee0899a532224846196f646921f3' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -84,7 +92,7 @@ test('configureDelegation', async () => { event.type === 'accountTransaction' && event.transactionType === 'configureDelegation' ) { - expect(event.events).toEqual(expected.configureDelegation); + expectToEqual(event.events, expected.configureDelegation); } else { throw Error('Wrong event.'); } @@ -92,8 +100,9 @@ test('configureDelegation', async () => { // Interrupted, Resumed, Transferred, Updated test('contract update', async () => { - const blockHash = - 'a74a3914143eb596132c74685fac1314f6d5e8bb393e3372e83726f0c4654de2'; + const blockHash = BlockHash.fromHexString( + 'a74a3914143eb596132c74685fac1314f6d5e8bb393e3372e83726f0c4654de2' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -102,7 +111,7 @@ test('contract update', async () => { event.type === 'accountTransaction' && event.transactionType === 'update' ) { - expect(event.events).toEqual(expected.updateEvent); + expectToEqual(event.events, expected.updateEvent); } else { throw Error('Wrong event.'); } @@ -110,8 +119,9 @@ test('contract update', async () => { // EncryptedSelfAmountAdded test('transferToEncrypted', async () => { - const blockHash = - '0254312274ccd192288ca49923c6571ae64d7d0ef57923a68d4c1b055e2ca757'; + const blockHash = BlockHash.fromHexString( + '0254312274ccd192288ca49923c6571ae64d7d0ef57923a68d4c1b055e2ca757' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -120,7 +130,7 @@ test('transferToEncrypted', async () => { event.type === 'accountTransaction' && event.transactionType === 'transferToEncrypted' ) { - expect(event.added).toEqual(expected.encryptedSelfAmountAddedEvent); + expectToEqual(event.added, expected.encryptedSelfAmountAddedEvent); } else { throw Error('Wrong event.'); } @@ -128,18 +138,20 @@ test('transferToEncrypted', async () => { // UpdateEnqueued test('UpdateEnqueued', async () => { - const blockHash = - '39122a9c720cae643b999d93dd7bf09bcf50e99bb716767dd35c39690390db54'; + const blockHash = BlockHash.fromHexString( + '39122a9c720cae643b999d93dd7bf09bcf50e99bb716767dd35c39690390db54' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); - expect(events[0]).toEqual(expected.updateEnqueuedEvent); + expectToEqual(events[0], expected.updateEnqueuedEvent); }); // ContractInitialized test('ContractInitialized', async () => { - const blockHash = - '70dbb294060878220505e928d616dde2d90cf5eeee0a92d3fdc1268334ace89e'; + const blockHash = BlockHash.fromHexString( + '70dbb294060878220505e928d616dde2d90cf5eeee0a92d3fdc1268334ace89e' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -148,7 +160,8 @@ test('ContractInitialized', async () => { event.type === 'accountTransaction' && event.transactionType === 'initContract' ) { - expect(event.contractInitialized).toEqual( + expectToEqual( + event.contractInitialized, expected.contractInitializedEvent ); } else { @@ -158,8 +171,9 @@ test('ContractInitialized', async () => { // ModuleDeployed test('ModuleDeployed', async () => { - const blockHash = - 'c7fd8efa319942d54336ccdfe8460a0591a2a4b3a6bac65fe552198d530105d1'; + const blockHash = BlockHash.fromHexString( + 'c7fd8efa319942d54336ccdfe8460a0591a2a4b3a6bac65fe552198d530105d1' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -168,7 +182,7 @@ test('ModuleDeployed', async () => { event.type === 'accountTransaction' && event.transactionType === 'deployModule' ) { - expect(event.moduleDeployed).toEqual(expected.moduleDeployedEvent); + expectToEqual(event.moduleDeployed, expected.moduleDeployedEvent); } else { throw Error('Wrong event.'); } @@ -176,8 +190,9 @@ test('ModuleDeployed', async () => { // DelegationRemoved test('DelegationRemoved', async () => { - const blockHash = - '65ad6b6a4c9eaccb99a01e2661fcc588a411beb0ed91d39ac692359d5a666631'; + const blockHash = BlockHash.fromHexString( + '65ad6b6a4c9eaccb99a01e2661fcc588a411beb0ed91d39ac692359d5a666631' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[1]; @@ -186,7 +201,7 @@ test('DelegationRemoved', async () => { event.type === 'accountTransaction' && event.transactionType === 'configureDelegation' ) { - expect(event.events[0]).toEqual(expected.delegationRemovedEvent); + expectToEqual(event.events[0], expected.delegationRemovedEvent); } else { throw Error('Wrong event.'); } @@ -194,8 +209,9 @@ test('DelegationRemoved', async () => { // TransferMemo test('TransferMemo', async () => { - const blockHash = - 'df96a12cc515bc863ed7021154494c8747e321565ff8b788066f0308c2963ece'; + const blockHash = BlockHash.fromHexString( + 'df96a12cc515bc863ed7021154494c8747e321565ff8b788066f0308c2963ece' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -204,7 +220,7 @@ test('TransferMemo', async () => { event.type === 'accountTransaction' && event.transactionType === 'transferWithMemo' ) { - expect(event).toEqual(expected.transferWithMemoSummary); + expectToEqual(event, expected.transferWithMemoSummary); } else { throw Error('Wrong event.'); } @@ -212,8 +228,9 @@ test('TransferMemo', async () => { // Upgraded test('Upgraded', async () => { - const blockHash = - '77ffdf2e8e4144a9a39b20ea7211a4aee0a23847778dcc1963c7a85f32b4f27d'; + const blockHash = BlockHash.fromHexString( + '77ffdf2e8e4144a9a39b20ea7211a4aee0a23847778dcc1963c7a85f32b4f27d' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -222,7 +239,7 @@ test('Upgraded', async () => { event.type === 'accountTransaction' && event.transactionType === 'update' ) { - expect(event.events[1]).toEqual(expected.upgradedEvent); + expectToEqual(event.events[1], expected.upgradedEvent); } else { throw Error('Wrong event.'); } @@ -230,8 +247,9 @@ test('Upgraded', async () => { // DataRegistered test('DataRegistered', async () => { - const blockHash = - 'ac4e60f4a014d823e3bf03859abdb2f9d2317b988dedc9c9621e3b7f5dcffb06'; + const blockHash = BlockHash.fromHexString( + 'ac4e60f4a014d823e3bf03859abdb2f9d2317b988dedc9c9621e3b7f5dcffb06' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -240,7 +258,7 @@ test('DataRegistered', async () => { event.type === 'accountTransaction' && event.transactionType === 'registerData' ) { - expect(event.dataRegistered).toEqual(expected.dataRegisteredEvent); + expectToEqual(event.dataRegistered, expected.dataRegisteredEvent); } else { throw Error('Wrong event.'); } @@ -248,8 +266,9 @@ test('DataRegistered', async () => { // NewEncryptedAmountEvent test('NewEncryptedAmountEvent', async () => { - const blockHash = - '4eec1470e133340859dd9cd39187ad5f32c5b59ca3c7277d44f9b30e7a563388'; + const blockHash = BlockHash.fromHexString( + '4eec1470e133340859dd9cd39187ad5f32c5b59ca3c7277d44f9b30e7a563388' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -258,7 +277,7 @@ test('NewEncryptedAmountEvent', async () => { event.type === 'accountTransaction' && event.transactionType === 'encryptedAmountTransfer' ) { - expect(event.added).toEqual(expected.newEncryptedAmountEvent); + expectToEqual(event.added, expected.newEncryptedAmountEvent); } else { throw Error('Wrong event.'); } @@ -266,8 +285,9 @@ test('NewEncryptedAmountEvent', async () => { // TransferWithScheduleEvent test('TransferWithScheduleEvent', async () => { - const blockHash = - '7696ce3b5e3c5165572984abb250f8ac7c8f42cdc5ca3e1c1f1c387bb878fc94'; + const blockHash = BlockHash.fromHexString( + '7696ce3b5e3c5165572984abb250f8ac7c8f42cdc5ca3e1c1f1c387bb878fc94' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -276,7 +296,7 @@ test('TransferWithScheduleEvent', async () => { event.type === 'accountTransaction' && event.transactionType === 'transferWithSchedule' ) { - expect(event.event).toEqual(expected.transferWithScheduleEvent); + expectToEqual(event.event, expected.transferWithScheduleEvent); } else { throw Error('Wrong event.'); } @@ -284,8 +304,9 @@ test('TransferWithScheduleEvent', async () => { // BakerKeysUpdated test('BakerKeysUpdated', async () => { - const blockHash = - 'ec886543ea454845ce09dcc064d7bc79f7da5a8c74c8f7cce9783681028a47de'; + const blockHash = BlockHash.fromHexString( + 'ec886543ea454845ce09dcc064d7bc79f7da5a8c74c8f7cce9783681028a47de' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[1]; @@ -294,7 +315,7 @@ test('BakerKeysUpdated', async () => { event.type === 'accountTransaction' && event.transactionType === 'configureBaker' ) { - expect(event.events[0]).toEqual(expected.bakerKeysUpdatedEvent); + expectToEqual(event.events[0], expected.bakerKeysUpdatedEvent); } else { throw Error('Wrong event:'); } @@ -302,8 +323,9 @@ test('BakerKeysUpdated', async () => { // BakerStakeIncreased test('BakerStakeIncreased', async () => { - const blockHash = - '29c4caa0de1d9fc9da9513635e876aa0db0c6ab37fc30e7d2d7883af51659273'; + const blockHash = BlockHash.fromHexString( + '29c4caa0de1d9fc9da9513635e876aa0db0c6ab37fc30e7d2d7883af51659273' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[1]; @@ -312,7 +334,7 @@ test('BakerStakeIncreased', async () => { event.type === 'accountTransaction' && event.transactionType === 'configureBaker' ) { - expect(event.events[0]).toEqual(expected.bakerStakeIncreasedEvent); + expectToEqual(event.events[0], expected.bakerStakeIncreasedEvent); } else { throw Error('Wrong event:'); } @@ -320,8 +342,9 @@ test('BakerStakeIncreased', async () => { // CredentialKeysUpdated test('CredentialKeysUpdated', async () => { - const blockHash = - '387a2f5812b16e4f6543e51007f20b514909de4d7ea39785b83bcd6f1cde9af4'; + const blockHash = BlockHash.fromHexString( + '387a2f5812b16e4f6543e51007f20b514909de4d7ea39785b83bcd6f1cde9af4' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -330,7 +353,7 @@ test('CredentialKeysUpdated', async () => { event.type === 'accountTransaction' && event.transactionType === 'updateCredentialKeys' ) { - expect(event.keysUpdated).toEqual(expected.credentialKeysUpdatedEvent); + expectToEqual(event.keysUpdated, expected.credentialKeysUpdatedEvent); } else { throw Error('Wrong event:'); } @@ -338,8 +361,9 @@ test('CredentialKeysUpdated', async () => { // CredentialsUpdated test('CredentialsUpdated', async () => { - const blockHash = - '6ce268765af0f59e147a0935980ae3014b9e90b9a43a2d9cf785f19641a9bf64'; + const blockHash = BlockHash.fromHexString( + '6ce268765af0f59e147a0935980ae3014b9e90b9a43a2d9cf785f19641a9bf64' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -348,7 +372,8 @@ test('CredentialsUpdated', async () => { event.type === 'accountTransaction' && event.transactionType === 'updateCredentials' ) { - expect(event.credentialsUpdated).toEqual( + expectToEqual( + event.credentialsUpdated, expected.credentialsUpdatedEvent ); } else { @@ -358,8 +383,9 @@ test('CredentialsUpdated', async () => { // BakerStakeDecreased test('BakerStakeDecreased', async () => { - const blockHash = - '2103b8c6f1e0608790f241b1ca5d19df16f00abe54e5885d72e60985959826ae'; + const blockHash = BlockHash.fromHexString( + '2103b8c6f1e0608790f241b1ca5d19df16f00abe54e5885d72e60985959826ae' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -368,7 +394,7 @@ test('BakerStakeDecreased', async () => { event.type === 'accountTransaction' && event.transactionType === 'configureBaker' ) { - expect(event.events[0]).toEqual(expected.bakerStakeDecreasedEvent); + expectToEqual(event.events[0], expected.bakerStakeDecreasedEvent); } else { throw Error('Wrong event:'); } @@ -376,8 +402,9 @@ test('BakerStakeDecreased', async () => { // DelegationStakeDecreased test('DelegationStakeDecreased', async () => { - const blockHash = - 'f0426a8937438551692bbd777ac61f309fa2adee2dc50c82d6bd6ff151f5ce0a'; + const blockHash = BlockHash.fromHexString( + 'f0426a8937438551692bbd777ac61f309fa2adee2dc50c82d6bd6ff151f5ce0a' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -386,7 +413,7 @@ test('DelegationStakeDecreased', async () => { event.type === 'accountTransaction' && event.transactionType === 'configureDelegation' ) { - expect(event.events[2]).toEqual(expected.delegationStakeDecreasedEvent); + expectToEqual(event.events[2], expected.delegationStakeDecreasedEvent); } else { throw Error('Wrong event:'); } diff --git a/packages/nodejs/test/getConsensusStatus.test.ts b/packages/nodejs/test/getConsensusStatus.test.ts index ffc244b96..86f06a06c 100644 --- a/packages/nodejs/test/getConsensusStatus.test.ts +++ b/packages/nodejs/test/getConsensusStatus.test.ts @@ -1,4 +1,4 @@ -import { ConsensusStatus, isHex } from '@concordium/common-sdk'; +import { ConsensusStatus } from '@concordium/common-sdk'; import { getNodeClientV2 as getNodeClient } from './testHelpers.js'; const client = getNodeClient(); @@ -6,9 +6,6 @@ test('retrieves the consensus status from the node with correct types', async () const consensusStatus: ConsensusStatus = await client.getConsensusStatus(); return Promise.all([ - expect(isHex(consensusStatus.bestBlock)).toBeTruthy(), - expect(isHex(consensusStatus.genesisBlock)).toBeTruthy(), - expect(isHex(consensusStatus.lastFinalizedBlock)).toBeTruthy(), expect( typeof consensusStatus.finalizationCount === 'bigint' ).toBeTruthy(), @@ -53,7 +50,6 @@ test('retrieves the consensus status from the node with correct types', async () ).toBeFalsy(), expect(Number.isNaN(consensusStatus.genesisIndex)).toBeFalsy(), - expect(typeof consensusStatus.epochDuration === 'bigint').toBeTruthy(), expect( typeof consensusStatus.bestBlockHeight === 'bigint' ).toBeTruthy(), diff --git a/packages/nodejs/test/rejectReasons.test.ts b/packages/nodejs/test/rejectReasons.test.ts index 729badae0..541ada102 100644 --- a/packages/nodejs/test/rejectReasons.test.ts +++ b/packages/nodejs/test/rejectReasons.test.ts @@ -1,13 +1,17 @@ -import { streamToList } from '@concordium/common-sdk'; +import { BlockHash, streamToList } from '@concordium/common-sdk'; import * as expected from './resources/expectedJsons.js'; -import { getNodeClientV2 as getNodeClient } from './testHelpers.js'; +import { + expectToEqual, + getNodeClientV2 as getNodeClient, +} from './testHelpers.js'; const client = getNodeClient(); // EncryptedAmountSelfTransfer test('EncryptedAmountSelfTransfer', async () => { - const blockHash = - 'a68ef25ac9b38dfb76884dc797f0b1f924695218107caed3b3e370479d552c3a'; + const blockHash = BlockHash.fromHexString( + 'a68ef25ac9b38dfb76884dc797f0b1f924695218107caed3b3e370479d552c3a' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -26,8 +30,9 @@ test('EncryptedAmountSelfTransfer', async () => { // FinalizationRewardCommissionNotInRange test('FinalizationRewardCommissionNotInRange', async () => { - const blockHash = - 'bb58a5dbcb77ec5d94d1039724e347a5a06b60bd098bb404c9967531e58ec870'; + const blockHash = BlockHash.fromHexString( + 'bb58a5dbcb77ec5d94d1039724e347a5a06b60bd098bb404c9967531e58ec870' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[1]; @@ -46,8 +51,9 @@ test('FinalizationRewardCommissionNotInRange', async () => { // DelegationTargetNotABaker test('DelegationTargetNotABaker', async () => { - const blockHash = - 'f885db7e2b27953f3f6f10b3c69bf7d9e77bc529768234e4191ecbc6fd4cc47d'; + const blockHash = BlockHash.fromHexString( + 'f885db7e2b27953f3f6f10b3c69bf7d9e77bc529768234e4191ecbc6fd4cc47d' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -66,8 +72,9 @@ test('DelegationTargetNotABaker', async () => { // AlreadyABaker test('AlreadyABaker', async () => { - const blockHash = - '20324be7fdb1dd2556e5492ac0b73df408bda7f237066cee3c3d71a4804327a4'; + const blockHash = BlockHash.fromHexString( + '20324be7fdb1dd2556e5492ac0b73df408bda7f237066cee3c3d71a4804327a4' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -84,8 +91,9 @@ test('AlreadyABaker', async () => { // NonExistentCredentialID test('NonExistentCredentialID', async () => { - const blockHash = - 'be5bd3b147eeababdbf19a0d60b29e2aeddc7eb65e3ab901cbd4f071d5af211c'; + const blockHash = BlockHash.fromHexString( + 'be5bd3b147eeababdbf19a0d60b29e2aeddc7eb65e3ab901cbd4f071d5af211c' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -104,8 +112,9 @@ test('NonExistentCredentialID', async () => { // ModuleNotWF test('ModuleNotWF', async () => { - const blockHash = - 'b100e5568b2db7cce2da671ac17d45911447d86340b40a469717c15fd4098dda'; + const blockHash = BlockHash.fromHexString( + 'b100e5568b2db7cce2da671ac17d45911447d86340b40a469717c15fd4098dda' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -122,8 +131,9 @@ test('ModuleNotWF', async () => { // AmountTooLarge test('AmountTooLarge', async () => { - const blockHash = - '25658e0353cae71a48f25f9ed92682cc096d1463b801676b449cb89c7fa13a1f'; + const blockHash = BlockHash.fromHexString( + '25658e0353cae71a48f25f9ed92682cc096d1463b801676b449cb89c7fa13a1f' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -132,7 +142,7 @@ test('AmountTooLarge', async () => { event.type === 'accountTransaction' && event.transactionType === 'failed' ) { - expect(event.rejectReason).toEqual(expected.amountTooLargeRejectReason); + expectToEqual(event.rejectReason, expected.amountTooLargeRejectReason); } else { throw Error('Wrong event'); } @@ -140,8 +150,9 @@ test('AmountTooLarge', async () => { // ModuleHashAlreadyExists test('ModuleHashAlreadyExists', async () => { - const blockHash = - 'ec85ac5f3b7a39ac277aee9e96837c53be3bd3442068a0970ab3badd80fd88e5'; + const blockHash = BlockHash.fromHexString( + 'ec85ac5f3b7a39ac277aee9e96837c53be3bd3442068a0970ab3badd80fd88e5' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -160,8 +171,9 @@ test('ModuleHashAlreadyExists', async () => { // TransactionFeeCommissionNotInRange test('TransactionFeeCommissionNotInRange', async () => { - const blockHash = - '102ef7df5a6d1502c6e2b864e182cbb10824d017e88bb90a4cb82e3c054e0bba'; + const blockHash = BlockHash.fromHexString( + '102ef7df5a6d1502c6e2b864e182cbb10824d017e88bb90a4cb82e3c054e0bba' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -180,8 +192,9 @@ test('TransactionFeeCommissionNotInRange', async () => { // StakeOverMaximumThresholdForPool test('StakeOverMaximumThresholdForPool', async () => { - const blockHash = - '5284633bd71b4f8840e9f2e86ced6a4615961248347669d7b5a5a7088422a9f0'; + const blockHash = BlockHash.fromHexString( + '5284633bd71b4f8840e9f2e86ced6a4615961248347669d7b5a5a7088422a9f0' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[1]; @@ -200,8 +213,9 @@ test('StakeOverMaximumThresholdForPool', async () => { // BakerInCooldown test('BakerInCooldown', async () => { - const blockHash = - 'dd47761affcc6446306158cd51b8ab117b81ae5d33413af2b3c4c5f20275fb5f'; + const blockHash = BlockHash.fromHexString( + 'dd47761affcc6446306158cd51b8ab117b81ae5d33413af2b3c4c5f20275fb5f' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -220,8 +234,9 @@ test('BakerInCooldown', async () => { // InvalidInitMethod test('InvalidInitMethod', async () => { - const blockHash = - '2830618959b146313cfc596826e59390f6b8907d33a964ec0663c1d7e975fcfa'; + const blockHash = BlockHash.fromHexString( + '2830618959b146313cfc596826e59390f6b8907d33a964ec0663c1d7e975fcfa' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -240,8 +255,9 @@ test('InvalidInitMethod', async () => { // InsufficientBalanceForDelegationStake test('InsufficientBalanceForDelegationStake', async () => { - const blockHash = - 'dce2ce0d5e893e273eb53726e35fb249e3151db2347c624e5d0c5ffce20c4950'; + const blockHash = BlockHash.fromHexString( + 'dce2ce0d5e893e273eb53726e35fb249e3151db2347c624e5d0c5ffce20c4950' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -260,8 +276,9 @@ test('InsufficientBalanceForDelegationStake', async () => { // InvalidAccountReference test('InvalidAccountReference', async () => { - const blockHash = - 'a37e065c239787a4fca3241580dd37ce354ef97224adf1f34afbf92fdd310b69'; + const blockHash = BlockHash.fromHexString( + 'a37e065c239787a4fca3241580dd37ce354ef97224adf1f34afbf92fdd310b69' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -280,8 +297,9 @@ test('InvalidAccountReference', async () => { // MissingBakerAddParameters test('MissingBakerAddParameters', async () => { - const blockHash = - '269d3730dd3813dbe5c8104be20bcfe02ee3fbd4a7a3da4fcca1271c38a6e405'; + const blockHash = BlockHash.fromHexString( + '269d3730dd3813dbe5c8104be20bcfe02ee3fbd4a7a3da4fcca1271c38a6e405' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -300,8 +318,9 @@ test('MissingBakerAddParameters', async () => { // PoolClosed test('PoolClosed', async () => { - const blockHash = - '72c2d0d9634b82ade18616711eb1cb351456b913d1758c4d840759a408b75775'; + const blockHash = BlockHash.fromHexString( + '72c2d0d9634b82ade18616711eb1cb351456b913d1758c4d840759a408b75775' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -318,8 +337,9 @@ test('PoolClosed', async () => { // ScheduledSelfTransfer test('ScheduledSelfTransfer', async () => { - const blockHash = - '917ca9e15667a667cad97c7806ea27b78633d6821cc6f1fa29f8aecd238223c5'; + const blockHash = BlockHash.fromHexString( + '917ca9e15667a667cad97c7806ea27b78633d6821cc6f1fa29f8aecd238223c5' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -338,8 +358,9 @@ test('ScheduledSelfTransfer', async () => { // InvalidModuleReference test('InvalidModuleReference', async () => { - const blockHash = - 'c6ebed14d387e8d0c3f8120f83d69948b39478d7205e468f4db9b089459ff8c4'; + const blockHash = BlockHash.fromHexString( + 'c6ebed14d387e8d0c3f8120f83d69948b39478d7205e468f4db9b089459ff8c4' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -358,8 +379,9 @@ test('InvalidModuleReference', async () => { // FirstScheduledReleaseExpired test('FirstScheduledReleaseExpired', async () => { - const blockHash = - '8692bbfd18983543aace1a04596e27ec8f332243b01ed2b6fed28397bf66ff89'; + const blockHash = BlockHash.fromHexString( + '8692bbfd18983543aace1a04596e27ec8f332243b01ed2b6fed28397bf66ff89' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -378,8 +400,9 @@ test('FirstScheduledReleaseExpired', async () => { // InvalidReceiveMethod test('InvalidReceiveMethod', async () => { - const blockHash = - '0b667b6886760c37a176097b390fd1d655e714f2bf19a507b3242d8ee919ed1a'; + const blockHash = BlockHash.fromHexString( + '0b667b6886760c37a176097b390fd1d655e714f2bf19a507b3242d8ee919ed1a' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -398,8 +421,9 @@ test('InvalidReceiveMethod', async () => { // InsufficientBalanceForBakerStake test('InsufficientBalanceForBakerStake', async () => { - const blockHash = - '1803d84dfaa081e5da1c1dc96bbb65888a65904cba5abcbfc2aad963d2d39097'; + const blockHash = BlockHash.fromHexString( + '1803d84dfaa081e5da1c1dc96bbb65888a65904cba5abcbfc2aad963d2d39097' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -418,8 +442,9 @@ test('InsufficientBalanceForBakerStake', async () => { // RuntimeFailure test('RuntimeFailure', async () => { - const blockHash = - '5072f24f681fc5ff9ae09f0b698f8aed20c02bd6990fc59bcb618252ad257355'; + const blockHash = BlockHash.fromHexString( + '5072f24f681fc5ff9ae09f0b698f8aed20c02bd6990fc59bcb618252ad257355' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -436,8 +461,9 @@ test('RuntimeFailure', async () => { // InvalidContractAddress test('InvalidContractAddress', async () => { - const blockHash = - '30247d68bcca12a0a611bfc412a9a8b28152f501ea957970f1351c528bd58edf'; + const blockHash = BlockHash.fromHexString( + '30247d68bcca12a0a611bfc412a9a8b28152f501ea957970f1351c528bd58edf' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -456,8 +482,9 @@ test('InvalidContractAddress', async () => { // OutOfEnergy test('OutOfEnergy', async () => { - const blockHash = - '57c632333f9373fbc7ea4ce3306269981560fd87c5a6de23b4a7584604e2c6bc'; + const blockHash = BlockHash.fromHexString( + '57c632333f9373fbc7ea4ce3306269981560fd87c5a6de23b4a7584604e2c6bc' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -474,8 +501,9 @@ test('OutOfEnergy', async () => { // InvalidEncryptedAmountTransferProof test('InvalidEncryptedAmountTransferProof', async () => { - const blockHash = - '6a63a548e2d983cafe65f47a785e1e1dde1ba35f6fe16234602936f4fbecb4dd'; + const blockHash = BlockHash.fromHexString( + '6a63a548e2d983cafe65f47a785e1e1dde1ba35f6fe16234602936f4fbecb4dd' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -494,8 +522,9 @@ test('InvalidEncryptedAmountTransferProof', async () => { // RejectedInit test('RejectedInit', async () => { - const blockHash = - 'b95031d150ae90175c203a63b23f8dafd5a8c57defaf5d287a6c534d4a4ad2d5'; + const blockHash = BlockHash.fromHexString( + 'b95031d150ae90175c203a63b23f8dafd5a8c57defaf5d287a6c534d4a4ad2d5' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -512,8 +541,9 @@ test('RejectedInit', async () => { // RejectedReceive test('RejectedReceive', async () => { - const blockHash = - '2141282b7a2ec57f3bcce59dc3b0649c80b872ae21a56c2ad300c4002145f988'; + const blockHash = BlockHash.fromHexString( + '2141282b7a2ec57f3bcce59dc3b0649c80b872ae21a56c2ad300c4002145f988' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -532,8 +562,9 @@ test('RejectedReceive', async () => { // StakeUnderMinimumThresholdForBaking test('StakeUnderMinimumThresholdForBaking', async () => { - const blockHash = - '4d8a001488e2295911b55822c9fb48fae7deff1bb1e2a36aba54c5f61b8e3159'; + const blockHash = BlockHash.fromHexString( + '4d8a001488e2295911b55822c9fb48fae7deff1bb1e2a36aba54c5f61b8e3159' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -552,8 +583,9 @@ test('StakeUnderMinimumThresholdForBaking', async () => { // InvalidTransferToPublicProof test('InvalidTransferToPublicProof', async () => { - const blockHash = - '10f02dba8e75ef25d2eefde19d39624c62600f13a5d91b857283b718017a4471'; + const blockHash = BlockHash.fromHexString( + '10f02dba8e75ef25d2eefde19d39624c62600f13a5d91b857283b718017a4471' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -572,8 +604,9 @@ test('InvalidTransferToPublicProof', async () => { // SerializationFailure test('SerializationFailure', async () => { - const blockHash = - 'd3e2e0a0a6674a56f9e057894fcba2244c21242705f9a95ba1052e6ab156eeb1'; + const blockHash = BlockHash.fromHexString( + 'd3e2e0a0a6674a56f9e057894fcba2244c21242705f9a95ba1052e6ab156eeb1' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; @@ -592,8 +625,9 @@ test('SerializationFailure', async () => { // PoolWouldBecomeOverDelegated test('PoolWouldBecomeOverDelegated', async () => { - const blockHash = - 'c4ae2d1e29ed2dfed7e4a0e08fb419ae6b5cef65cba9ff0c6553ef6377b3e95c'; + const blockHash = BlockHash.fromHexString( + 'c4ae2d1e29ed2dfed7e4a0e08fb419ae6b5cef65cba9ff0c6553ef6377b3e95c' + ); const eventStream = client.getBlockTransactionEvents(blockHash); const events = await streamToList(eventStream); const event = events[0]; diff --git a/packages/nodejs/test/resources/expectedJsons.ts b/packages/nodejs/test/resources/expectedJsons.ts index 770f6b3a8..aee7370fc 100644 --- a/packages/nodejs/test/resources/expectedJsons.ts +++ b/packages/nodejs/test/resources/expectedJsons.ts @@ -1,14 +1,63 @@ import { AccountAddress, + AccountCreationSummary, + AccountInfo, + AmountAddedByDecryptionEvent, + AmountTooLarge, + BakerEvent, + BakerPoolPendingChangeType, + BakerPoolStatus, + BaseAccountTransactionSummary, + BlockFinalizationSummary, + BlockHash, BlockInfoV0, + BlockItemStatus, + BlockItemSummary, + BlockSpecialEvent, CcdAmount, ChainParametersV0, ChainParametersV1, + ContractAddress, + ContractInitializedEvent, + ContractTraceEvent, + CredentialKeysUpdatedEvent, + CredentialsUpdatedEvent, + DataRegisteredEvent, + DelegationEvent, + DelegationTargetType, + DelegatorInfo, + DelegatorRewardPeriodInfo, ElectionInfoV0, + EncryptedAmountsRemovedEvent, + EncryptedSelfAmountAddedEvent, Energy, + InitName, InstanceInfo, + InvalidContractAddress, + InvokeContractResult, + ModuleDeployedEvent, ModuleReference, + NewEncryptedAmountEvent, NextUpdateSequenceNumbers, + OpenStatusText, + Parameter, + PendingUpdate, + PoolStatusType, + ReceiveName, + RejectReasonTag, + RejectedReceive, + ReturnValue, + SequenceNumber, + StakePendingChangeType, + TransactionEventTag, + TransactionHash, + TransactionKindString, + TransactionStatusEnum, + TransactionSummaryType, + TransferWithMemoSummary, + TransferredWithScheduleEvent, + UpdateSummary, + UpdateType, } from '@concordium/common-sdk'; export const accountInfo = { @@ -139,19 +188,22 @@ export const stakingInfoDelegator = { }, }; -export const blockItemStatusUpdate = { - status: 'finalized', +export const blockItemStatusUpdate: BlockItemStatus = { + status: TransactionStatusEnum.Finalized, outcome: { - blockHash: - '2d9e1a081819ad8dbf81d5a882ea2f5352cb3429fc12b0ec18c131a360751a66', + blockHash: BlockHash.fromHexString( + '2d9e1a081819ad8dbf81d5a882ea2f5352cb3429fc12b0ec18c131a360751a66' + ), summary: { index: 0n, - energyCost: 0n, - hash: '3de823b876d05cdd33a311a0f84124079f5f677afb2534c4943f830593edc650', - type: 'updateTransaction', + energyCost: Energy.create(0), + hash: TransactionHash.fromHexString( + '3de823b876d05cdd33a311a0f84124079f5f677afb2534c4943f830593edc650' + ), + type: TransactionSummaryType.UpdateTransaction, effectiveTime: 0n, payload: { - updateType: 'microGtuPerEuro', + updateType: UpdateType.MicroGtuPerEuro, update: { numerator: 17592435270983729152n, denominator: 163844642115n, @@ -161,23 +213,30 @@ export const blockItemStatusUpdate = { }, }; -export const blockItemStatusTransfer = { - status: 'finalized', +export const blockItemStatusTransfer: BlockItemStatus = { + status: TransactionStatusEnum.Finalized, outcome: { - blockHash: - '577513ab772da146c7abb9f30c521668d7ef4fa01f4838cc51d5f59e27c7a5fc', + blockHash: BlockHash.fromHexString( + '577513ab772da146c7abb9f30c521668d7ef4fa01f4838cc51d5f59e27c7a5fc' + ), summary: { - type: 'accountTransaction', + type: TransactionSummaryType.AccountTransaction, index: 0n, cost: 1480606n, - energyCost: 501n, - hash: '502332239efc0407eebef5c73c390080e5d7e1b127ff29f786a62b3c9ab6cfe7', - sender: '4fKPBDf9r5vhEpoeNY7SJbZv8bAJvYYyJSEggZkNyQPgao8iLy', - transactionType: 'transfer', + energyCost: Energy.create(501), + hash: TransactionHash.fromHexString( + '502332239efc0407eebef5c73c390080e5d7e1b127ff29f786a62b3c9ab6cfe7' + ), + sender: AccountAddress.fromBase58( + '4fKPBDf9r5vhEpoeNY7SJbZv8bAJvYYyJSEggZkNyQPgao8iLy' + ), + transactionType: TransactionKindString.Transfer, transfer: { amount: 1000000n, - tag: 'Transferred', - to: '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj', + tag: TransactionEventTag.Transferred, + to: AccountAddress.fromBase58( + '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj' + ), }, }, }, @@ -189,38 +248,39 @@ export const instanceInfo: InstanceInfo = { '4Y1c27ZRpRut9av69n3i1uhfeDp4XGuvsm9fkEjFvgpoxXWxQB' ), amount: new CcdAmount(0n), - methods: ['weather.get', 'weather.set'], - name: 'init_weather', + methods: ['weather.get', 'weather.set'].map( + ReceiveName.fromStringUnchecked + ), + name: InitName.fromStringUnchecked('init_weather'), sourceModule: new ModuleReference( '67d568433bd72e4326241f262213d77f446db8ba03dfba351ae35c1b2e7e5109' ), }; -export const invokeInstanceResponseV0 = { +export const invokeInstanceResponseV0: InvokeContractResult = { tag: 'success', - usedEnergy: 342n, + usedEnergy: Energy.create(342), returnValue: undefined, events: [ { - tag: 'Updated', + tag: TransactionEventTag.Updated, events: [], amount: 1n, - address: { - index: 6n, - subindex: 0n, - }, + address: ContractAddress.create(6), contractVersion: 0, instigator: { type: 'AddressAccount', - address: '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G', + address: AccountAddress.fromBase58( + '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G' + ), }, - message: '', - receiveName: 'PiggyBank.insert', + message: Parameter.empty(), + receiveName: ReceiveName.fromStringUnchecked('PiggyBank.insert'), }, ], }; -export const accountList = [ +export const accountList: AccountAddress.Type[] = [ '3QK1rxUXV7GRk4Ng7Bs7qnbkdjyBdjzCytpTrSQN7BaJkiEfgZ', '3U4sfVSqGG6XK8g6eho2qRYtnHc4MWJBG1dfxdtPGbfHwFxini', '3gGBYDSpx2zWL3YMcqD48U5jVXYG4pJBDZqeY5CbMMKpxVBbc3', @@ -234,7 +294,7 @@ export const accountList = [ '4AnukgcopMC4crxfL1L9fUYw9MAkoo1yKLvH7eA1NAX7SxgyRY', '4BTFaHx8CioLi8Xe7YiimpAK1oQMkbx5Wj6B8N7d7NXgmLvEZs', '4EJJ1hVhbVZT2sR9xPzWUwFcJWK3fPX54z94zskTozFVk8Xd4L', -]; +].map(AccountAddress.fromBase58); export const moduleList = [ '67d568433bd72e4326241f262213d77f446db8ba03dfba351ae35c1b2e7e5109', @@ -242,11 +302,11 @@ export const moduleList = [ 'ceb018e4cd3456c0ccc0bca14285a69fd55f4cb09c322195d49c5c22f85930fe', ]; -export const ancestorList = [ +export const ancestorList: BlockHash.Type[] = [ 'fe88ff35454079c3df11d8ae13d5777babd61f28be58494efe51b6593e30716e', '28d92ec42dbda119f0b0207d3400b0573fe8baf4b0d3dbe44b86781ad6b655cf', 'abc98d4866e92b0ac4722d523aee96cafcdd127694d565c532e149616dbad96c', -]; +].map(BlockHash.fromHexString); export const instanceStateList = [ { @@ -337,55 +397,75 @@ export const arList = [ }, ]; -export const delegatorInfoList = [ +export const delegatorInfoList: DelegatorInfo[] = [ { - account: '3uX8g2uzQwBjVSJ6ZDU5cQCKhgsET6kMuRoraQH2ANB9Xa84YR', + account: AccountAddress.fromBase58( + '3uX8g2uzQwBjVSJ6ZDU5cQCKhgsET6kMuRoraQH2ANB9Xa84YR' + ), stake: 40000000000n, }, { - account: '4mAs6xcFw26fb6u8odkJWoe3fAK8bCJ91BwScUc36DFhh3thwD', + account: AccountAddress.fromBase58( + '4mAs6xcFw26fb6u8odkJWoe3fAK8bCJ91BwScUc36DFhh3thwD' + ), stake: 10000000n, }, { - account: '3NvUNvVm5puDT2EYbo7hCF3d5AwzzCqKE18Ms6BYkKY9UShdf3', + account: AccountAddress.fromBase58( + '3NvUNvVm5puDT2EYbo7hCF3d5AwzzCqKE18Ms6BYkKY9UShdf3' + ), stake: 3000000000n, }, { - account: '3ivPxmqdRk5TX5mKpFshKzrA44bYUW2tg6EwDPvALszNoBGTK9', + account: AccountAddress.fromBase58( + '3ivPxmqdRk5TX5mKpFshKzrA44bYUW2tg6EwDPvALszNoBGTK9' + ), stake: 33000000n, }, { - account: '37tU96v4MQSaEgVP68M3TBRHMwZpgYSGnMer3ta3FJ8wkXtjDQ', + account: AccountAddress.fromBase58( + '37tU96v4MQSaEgVP68M3TBRHMwZpgYSGnMer3ta3FJ8wkXtjDQ' + ), stake: 94000000n, }, ]; -export const passiveDelegatorInfoList = [ +export const passiveDelegatorInfoList: DelegatorInfo[] = [ { - account: '4gCvJ91EeYzsTzwiC7Kr4AcFzSuDmf5wxev7FRzU3uw49WamBm', + account: AccountAddress.fromBase58( + '4gCvJ91EeYzsTzwiC7Kr4AcFzSuDmf5wxev7FRzU3uw49WamBm' + ), stake: 1900000000n, }, { - account: '4mQweXtq3zHwS7CtK5fjWkpJDUvtUSKycNa8xaEbe6kErGeXcL', + account: AccountAddress.fromBase58( + '4mQweXtq3zHwS7CtK5fjWkpJDUvtUSKycNa8xaEbe6kErGeXcL' + ), stake: 1000000000n, }, { - account: '3irV7FF3BZbz9ejGTm7EHLUi6CQHdJUELDfyhwkHcLqXmQyUfR', + account: AccountAddress.fromBase58( + '3irV7FF3BZbz9ejGTm7EHLUi6CQHdJUELDfyhwkHcLqXmQyUfR' + ), stake: 100000000n, pendingChange: { effectiveTime: new Date('2022-06-28T11:47:37.750Z'), - change: 'RemoveStake', + change: StakePendingChangeType.RemoveStakeV1, }, }, ]; -export const passiveDelegatorRewardInfoList = [ +export const passiveDelegatorRewardInfoList: DelegatorRewardPeriodInfo[] = [ { - account: '4gCvJ91EeYzsTzwiC7Kr4AcFzSuDmf5wxev7FRzU3uw49WamBm', + account: AccountAddress.fromBase58( + '4gCvJ91EeYzsTzwiC7Kr4AcFzSuDmf5wxev7FRzU3uw49WamBm' + ), stake: 1900000000n, }, { - account: '4mQweXtq3zHwS7CtK5fjWkpJDUvtUSKycNa8xaEbe6kErGeXcL', + account: AccountAddress.fromBase58( + '4mQweXtq3zHwS7CtK5fjWkpJDUvtUSKycNa8xaEbe6kErGeXcL' + ), stake: 1000000000n, }, ]; @@ -397,71 +477,95 @@ export const electionInfoList: ElectionInfoV0 = { bakerElectionInfo: [ { baker: 0n, - account: '48XGRnvQoG92T1AwETvW5pnJ1aRSPMKsWtGdKhTqyiNZzMk3Qn', + account: AccountAddress.fromBase58( + '48XGRnvQoG92T1AwETvW5pnJ1aRSPMKsWtGdKhTqyiNZzMk3Qn' + ), lotteryPower: 0.09090909090909091, }, { baker: 1n, - account: '3U4sfVSqGG6XK8g6eho2qRYtnHc4MWJBG1dfxdtPGbfHwFxini', + account: AccountAddress.fromBase58( + '3U4sfVSqGG6XK8g6eho2qRYtnHc4MWJBG1dfxdtPGbfHwFxini' + ), lotteryPower: 0.09090909090909091, }, { baker: 2n, - account: '3QK1rxUXV7GRk4Ng7Bs7qnbkdjyBdjzCytpTrSQN7BaJkiEfgZ', + account: AccountAddress.fromBase58( + '3QK1rxUXV7GRk4Ng7Bs7qnbkdjyBdjzCytpTrSQN7BaJkiEfgZ' + ), lotteryPower: 0.09090909090909091, }, { baker: 3n, - account: '3gGBYDSpx2zWL3YMcqD48U5jVXYG4pJBDZqeY5CbMMKpxVBbc3', + account: AccountAddress.fromBase58( + '3gGBYDSpx2zWL3YMcqD48U5jVXYG4pJBDZqeY5CbMMKpxVBbc3' + ), lotteryPower: 0.09090909090909091, }, { baker: 4n, - account: '44Axe5eHnMkBinX7GKvUm5w6mX83JGdasijhvsMv5ZW2Wmgphg', + account: AccountAddress.fromBase58( + '44Axe5eHnMkBinX7GKvUm5w6mX83JGdasijhvsMv5ZW2Wmgphg' + ), lotteryPower: 0.09090909090909091, }, { baker: 5n, - account: '4EJJ1hVhbVZT2sR9xPzWUwFcJWK3fPX54z94zskTozFVk8Xd4L', + account: AccountAddress.fromBase58( + '4EJJ1hVhbVZT2sR9xPzWUwFcJWK3fPX54z94zskTozFVk8Xd4L' + ), lotteryPower: 0.09090909090909091, }, { baker: 6n, - account: '3ntvNGT6tDuLYiSb5gMJSQAZfLPUJnzoizcFiVRWqLoctuXxpK', + account: AccountAddress.fromBase58( + '3ntvNGT6tDuLYiSb5gMJSQAZfLPUJnzoizcFiVRWqLoctuXxpK' + ), lotteryPower: 0.09090909090909091, }, { baker: 7n, - account: '4BTFaHx8CioLi8Xe7YiimpAK1oQMkbx5Wj6B8N7d7NXgmLvEZs', + account: AccountAddress.fromBase58( + '4BTFaHx8CioLi8Xe7YiimpAK1oQMkbx5Wj6B8N7d7NXgmLvEZs' + ), lotteryPower: 0.09090909090909091, }, { baker: 8n, - account: '4AnukgcopMC4crxfL1L9fUYw9MAkoo1yKLvH7eA1NAX7SxgyRY', + account: AccountAddress.fromBase58( + '4AnukgcopMC4crxfL1L9fUYw9MAkoo1yKLvH7eA1NAX7SxgyRY' + ), lotteryPower: 0.09090909090909091, }, { baker: 9n, - account: '3y9DtDUL8xpf8i2yj9k44zMVkf4H1hkpBEQcXbJhrgcwYSGg41', + account: AccountAddress.fromBase58( + '3y9DtDUL8xpf8i2yj9k44zMVkf4H1hkpBEQcXbJhrgcwYSGg41' + ), lotteryPower: 0.09090909090909091, }, { baker: 10n, - account: '42tFTDWvTmBd7hEacohuCfGFa9TsBKhsmXKeViQ7q7NoY7UadV', + account: AccountAddress.fromBase58( + '42tFTDWvTmBd7hEacohuCfGFa9TsBKhsmXKeViQ7q7NoY7UadV' + ), lotteryPower: 0.09090909090909091, }, ], }; -export const transactionEventList = [ +export const transactionEventList: BlockItemSummary[] = [ { - type: 'updateTransaction', + type: TransactionSummaryType.UpdateTransaction, index: 0n, - energyCost: 0n, - hash: '49d7b5c3234dc17bd904af0b63712dc0a6680b96ad556c5ac1103d8cdd128891', + energyCost: Energy.create(0), + hash: TransactionHash.fromHexString( + '49d7b5c3234dc17bd904af0b63712dc0a6680b96ad556c5ac1103d8cdd128891' + ), effectiveTime: 0n, payload: { - updateType: 'microGtuPerEuro', + updateType: UpdateType.MicroGtuPerEuro, update: { denominator: 126230907181n, numerator: 9397474320418127872n, @@ -492,7 +596,7 @@ export const seqNums: NextUpdateSequenceNumbers = { finalizationCommiteeParameters: 1n, }; -export const specialEventList = [ +export const specialEventList: BlockSpecialEvent[] = [ { tag: 'blockAccrueReward', transactionFees: 0n, @@ -505,9 +609,9 @@ export const specialEventList = [ }, ]; -export const pendingUpdateList = [ +export const pendingUpdateList: PendingUpdate[] = [ { - updateType: 'protocol', + updateType: UpdateType.Protocol, update: { message: 'Enable protocol version 5', specificationHash: @@ -519,10 +623,12 @@ export const pendingUpdateList = [ }, ]; -export const blockFinalizationSummary = { +export const blockFinalizationSummary: BlockFinalizationSummary = { tag: 'record', record: { - block: '28d92ec42dbda119f0b0207d3400b0573fe8baf4b0d3dbe44b86781ad6b655cf', + block: BlockHash.fromHexString( + '28d92ec42dbda119f0b0207d3400b0573fe8baf4b0d3dbe44b86781ad6b655cf' + ), index: 1131614n, delay: 0n, finalizers: [ @@ -540,20 +646,29 @@ export const blockFinalizationSummary = { }, }; -export const accountCreationEvent = { - type: 'accountCreation', +export const accountCreationEvent: AccountCreationSummary = { + type: TransactionSummaryType.AccountCreation, index: 0n, - energyCost: 54100n, - hash: '9931f541e166d86916354fc98759fcad604d447041142c0897f473093aaafdb5', + energyCost: Energy.create(54100), + hash: TransactionHash.fromHexString( + '9931f541e166d86916354fc98759fcad604d447041142c0897f473093aaafdb5' + ), credentialType: 'normal', - address: '32YGU1j7Z3xwA5URGYFrMamKj7JtfGvXFiXH4p3gAKdrpJcdg2', + address: AccountAddress.fromBase58( + '32YGU1j7Z3xwA5URGYFrMamKj7JtfGvXFiXH4p3gAKdrpJcdg2' + ), regId: '9015cfd6c1bd06f0e0355fc5355a0c18fe0cb37632d469b07d6fbfa9c05facc271c975466d8dfe3144c683f44fd0af71', }; -export const transferToPublicEvent = [ +export const transferToPublicEvent: [ + EncryptedAmountsRemovedEvent, + AmountAddedByDecryptionEvent +] = [ { - tag: 'EncryptedAmountsRemoved', - account: '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj', + tag: TransactionEventTag.EncryptedAmountsRemoved, + account: AccountAddress.fromBase58( + '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj' + ), inputAmount: 'b74e0a607e30eefc5e9323befdbebae158f66c0f6767d3c3f3ff4b1a9d5b9f0e5e565d734141bd82bfca4bcf32e2bec182e895b7afde650cd2e51c2d704d58965b0c462ffef2fca87204ac5248b111290b699dfe84887aa11ab357dab4b2ba00b3301a5e0fbc6cd3f9ac58bbf19abcc9a56ecc83a16738508fb9ec60da2818d5360dbf66839c6a4037e37c2a4a64956ab5c30c0bf1ed90713838dd8a6cce803111698f9c0e145cae6be38e4136ebdc6205ac4ca2f43852dac7e7f6d37fc55cdc', newAmount: @@ -561,16 +676,20 @@ export const transferToPublicEvent = [ upToIndex: 0, }, { - tag: 'AmountAddedByDecryption', - account: '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj', + tag: TransactionEventTag.AmountAddedByDecryption, + account: AccountAddress.fromBase58( + '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj' + ), amount: 1000000n, }, ]; -export const configureBaker = [ +export const configureBaker: BakerEvent[] = [ { - tag: 'BakerAdded', - account: '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS', + tag: TransactionEventTag.BakerAdded, + account: AccountAddress.fromBase58( + '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS' + ), aggregationKey: '802f086e91d71a4d8e1437229b4b7f39c2f45ee1a075e4b786f60af7ec278fa0052318f3f65989cd0cdd0e9ef17b865710b59ef9b894f1f4fb6a58ebbef7b07a04a503421cfa37229c66a9fe8e943be47fba7b15eb263227224e35e0ff088fda', bakerId: 2561n, @@ -582,275 +701,323 @@ export const configureBaker = [ stake: 15000000000n, }, { - tag: 'BakerSetRestakeEarnings', - account: '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS', + tag: TransactionEventTag.BakerSetRestakeEarnings, + account: AccountAddress.fromBase58( + '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS' + ), bakerId: 2561n, restakeEarnings: true, }, { - tag: 'BakerSetOpenStatus', - account: '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS', + tag: TransactionEventTag.BakerSetOpenStatus, + account: AccountAddress.fromBase58( + '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS' + ), bakerId: 2561n, - openStatus: 'openForAll', + openStatus: OpenStatusText.OpenForAll, }, { - tag: 'BakerSetMetadataURL', - account: '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS', + tag: TransactionEventTag.BakerSetMetadataURL, + account: AccountAddress.fromBase58( + '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS' + ), bakerId: 2561n, metadataURL: '', }, { - tag: 'BakerSetTransactionFeeCommission', - account: '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS', + tag: TransactionEventTag.BakerSetTransactionFeeCommission, + account: AccountAddress.fromBase58( + '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS' + ), bakerId: 2561n, transactionFeeCommission: 0.1, }, { - tag: 'BakerSetBakingRewardCommission', - account: '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS', + tag: TransactionEventTag.BakerSetBakingRewardCommission, + account: AccountAddress.fromBase58( + '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS' + ), bakerId: 2561n, bakingRewardCommission: 0.1, }, { - tag: 'BakerSetFinalizationRewardCommission', - account: '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS', + tag: TransactionEventTag.BakerSetFinalizationRewardCommission, + account: AccountAddress.fromBase58( + '2zdNDFqqn6pGPzEVRLTLNfBX6FTyQECjAgdLWqYEvBsv7uRjSS' + ), bakerId: 2561n, finalizationRewardCommission: 1, }, ]; -export const bakerRemoved = { - tag: 'BakerRemoved', +export const bakerRemoved: BakerEvent = { + tag: TransactionEventTag.BakerRemoved, bakerId: 1879n, - account: '4aCoaW3qkQRnY3fUGThQcEMGSPLUEQ7XL9Yagx2UR91QpvtoAe', + account: AccountAddress.fromBase58( + '4aCoaW3qkQRnY3fUGThQcEMGSPLUEQ7XL9Yagx2UR91QpvtoAe' + ), }; -export const configureDelegation = [ +export const configureDelegation: DelegationEvent[] = [ { - account: '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj', + account: AccountAddress.fromBase58( + '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj' + ), delegatorId: 2059, - tag: 'DelegationAdded', + tag: TransactionEventTag.DelegationAdded, }, { - account: '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj', - delegationTarget: { delegateType: 'Passive' }, + account: AccountAddress.fromBase58( + '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj' + ), + delegationTarget: { + delegateType: DelegationTargetType.PassiveDelegation, + }, delegatorId: 2059, - tag: 'DelegationSetDelegationTarget', + tag: TransactionEventTag.DelegationSetDelegationTarget, }, { - account: '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj', + account: AccountAddress.fromBase58( + '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj' + ), delegatorId: 2059, restakeEarnings: true, - tag: 'DelegationSetRestakeEarnings', + tag: TransactionEventTag.DelegationSetRestakeEarnings, }, { - account: '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj', + account: AccountAddress.fromBase58( + '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj' + ), delegatorId: 2059, newStake: 1000000n, - tag: 'DelegationStakeIncreased', + tag: TransactionEventTag.DelegationStakeIncreased, }, ]; -export const updateEvent = [ +export const updateEvent: ContractTraceEvent[] = [ { - address: { index: 866n, subindex: 0n }, + address: ContractAddress.create(866), events: [], - tag: 'Interrupted', + tag: TransactionEventTag.Interrupted, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), events: [], - tag: 'Interrupted', + tag: TransactionEventTag.Interrupted, }, { - address: { index: 864n, subindex: 0n }, + address: ContractAddress.create(864), amount: 0n, contractVersion: 1, events: [], instigator: { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), type: 'AddressContract', }, - message: '0000', - receiveName: 'CIS2-wCCD-State.getPaused', - tag: 'Updated', + message: Parameter.fromHexString('0000'), + receiveName: ReceiveName.fromStringUnchecked( + 'CIS2-wCCD-State.getPaused' + ), + tag: TransactionEventTag.Updated, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), success: true, - tag: 'Resumed', + tag: TransactionEventTag.Resumed, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), events: [], - tag: 'Interrupted', + tag: TransactionEventTag.Interrupted, }, { - address: { index: 864n, subindex: 0n }, + address: ContractAddress.create(864), amount: 0n, contractVersion: 1, events: [], instigator: { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), type: 'AddressContract', }, - message: - '00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083', - receiveName: 'CIS2-wCCD-State.getBalance', - tag: 'Updated', + message: Parameter.fromHexString( + '00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083' + ), + receiveName: ReceiveName.fromStringUnchecked( + 'CIS2-wCCD-State.getBalance' + ), + tag: TransactionEventTag.Updated, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), success: true, - tag: 'Resumed', + tag: TransactionEventTag.Resumed, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), events: [], - tag: 'Interrupted', + tag: TransactionEventTag.Interrupted, }, { - address: { index: 864n, subindex: 0n }, + address: ContractAddress.create(864), amount: 0n, contractVersion: 1, events: [], instigator: { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), type: 'AddressContract', }, - message: - '00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083c0843d00', - receiveName: 'CIS2-wCCD-State.setBalance', - tag: 'Updated', + message: Parameter.fromHexString( + '00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083c0843d00' + ), + receiveName: ReceiveName.fromStringUnchecked( + 'CIS2-wCCD-State.setBalance' + ), + tag: TransactionEventTag.Updated, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), success: true, - tag: 'Resumed', + tag: TransactionEventTag.Resumed, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), events: [], - tag: 'Interrupted', + tag: TransactionEventTag.Interrupted, }, { - address: { index: 866n, subindex: 0n }, + address: ContractAddress.create(866), events: [], - tag: 'Interrupted', + tag: TransactionEventTag.Interrupted, }, { amount: 1000000n, from: { - address: { index: 866n, subindex: 0n }, + address: ContractAddress.create(866), type: 'AddressContract', }, - tag: 'Transferred', + tag: TransactionEventTag.Transferred, to: { - address: '4inf4g36xDEQmjxDbbkqeHD2HNg9v7dohXUDH5S9en4Th53kxm', + address: AccountAddress.fromBase58( + '4inf4g36xDEQmjxDbbkqeHD2HNg9v7dohXUDH5S9en4Th53kxm' + ), type: 'AddressAccount', }, }, { - address: { index: 866n, subindex: 0n }, + address: ContractAddress.create(866), success: true, - tag: 'Resumed', + tag: TransactionEventTag.Resumed, }, { - address: { index: 866n, subindex: 0n }, + address: ContractAddress.create(866), amount: 0n, contractVersion: 1, events: [], instigator: { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), type: 'AddressContract', }, - message: - 'c0843d00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be000830000', - receiveName: 'CIS2-wCCD-Proxy.transferCCD', - tag: 'Updated', + message: Parameter.fromHexString( + 'c0843d00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be000830000' + ), + receiveName: ReceiveName.fromStringUnchecked( + 'CIS2-wCCD-Proxy.transferCCD' + ), + tag: TransactionEventTag.Updated, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), success: true, - tag: 'Resumed', + tag: TransactionEventTag.Resumed, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), events: [], - tag: 'Interrupted', + tag: TransactionEventTag.Interrupted, }, { - address: { index: 866n, subindex: 0n }, + address: ContractAddress.create(866), amount: 0n, contractVersion: 1, events: [ 'fd00c0843d00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083', ], instigator: { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), type: 'AddressContract', }, - message: - 'fd00c0843d00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083', - receiveName: 'CIS2-wCCD-Proxy.logEvent', - tag: 'Updated', + message: Parameter.fromHexString( + 'fd00c0843d00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083' + ), + receiveName: ReceiveName.fromStringUnchecked( + 'CIS2-wCCD-Proxy.logEvent' + ), + tag: TransactionEventTag.Updated, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), success: true, - tag: 'Resumed', + tag: TransactionEventTag.Resumed, }, { - address: { index: 865n, subindex: 0n }, + address: ContractAddress.create(865), amount: 0n, contractVersion: 1, events: [], instigator: { - address: { index: 866n, subindex: 0n }, + address: ContractAddress.create(866), type: 'AddressContract', }, - message: - 'c0843d00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be0008300e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083000000e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083', - receiveName: 'CIS2-wCCD.unwrap', - tag: 'Updated', + message: Parameter.fromHexString( + 'c0843d00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be0008300e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083000000e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be00083' + ), + receiveName: ReceiveName.fromStringUnchecked('CIS2-wCCD.unwrap'), + tag: TransactionEventTag.Updated, }, { - address: { index: 866n, subindex: 0n }, + address: ContractAddress.create(866), success: true, - tag: 'Resumed', + tag: TransactionEventTag.Resumed, }, { - address: { index: 866n, subindex: 0n }, + address: ContractAddress.create(866), amount: 0n, contractVersion: 1, events: [], instigator: { - address: '4inf4g36xDEQmjxDbbkqeHD2HNg9v7dohXUDH5S9en4Th53kxm', + address: AccountAddress.fromBase58( + '4inf4g36xDEQmjxDbbkqeHD2HNg9v7dohXUDH5S9en4Th53kxm' + ), type: 'AddressAccount', }, - message: - 'c0843d00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be0008300e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be000830000', - receiveName: 'CIS2-wCCD-Proxy.unwrap', - tag: 'Updated', + message: Parameter.fromHexString( + 'c0843d00e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be0008300e9f89f76878691716298685f21637d86fd8c98de7baa1d67e0ce11241be000830000' + ), + receiveName: ReceiveName.fromStringUnchecked('CIS2-wCCD-Proxy.unwrap'), + tag: TransactionEventTag.Updated, }, ]; -export const encryptedSelfAmountAddedEvent = { - account: '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj', +export const encryptedSelfAmountAddedEvent: EncryptedSelfAmountAddedEvent = { + account: AccountAddress.fromBase58( + '3BpVX13dw29JruyMzCfde96hoB7DtQ53WMGVDMrmPtuYAbzADj' + ), amount: 10000000n, newAmount: 'c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098c71824023d5fb1bca5accb3ac010551e4af7e9988cd0ef309ee37149ef7843af6f294e79b8fcbda9b4f4ed094d66cbc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', - tag: 'EncryptedSelfAmountAdded', + tag: TransactionEventTag.EncryptedSelfAmountAdded, }; -export const updateEnqueuedEvent = { - type: 'updateTransaction', +export const updateEnqueuedEvent: UpdateSummary = { + type: TransactionSummaryType.UpdateTransaction, index: 0n, - energyCost: 0n, - hash: 'f296a32603fc14aa679001c49a4db1b2133787ae37743536938ec51382fb8392', + energyCost: Energy.create(0), + hash: TransactionHash.fromHexString( + 'f296a32603fc14aa679001c49a4db1b2133787ae37743536938ec51382fb8392' + ), effectiveTime: 1669115100n, payload: { - updateType: 'protocol', + updateType: UpdateType.Protocol, update: { message: 'Enable protocol version 5', specificationHash: @@ -861,9 +1028,11 @@ export const updateEnqueuedEvent = { }, }, }; -export const transferWithScheduleEvent = { - tag: 'TransferredWithSchedule', - to: '3ySdbNTPogmvUBD5g42FaZqYht78jQZ2jose9yZFkCj8zyCGWt', +export const transferWithScheduleEvent: TransferredWithScheduleEvent = { + tag: TransactionEventTag.TransferredWithSchedule, + to: AccountAddress.fromBase58( + '3ySdbNTPogmvUBD5g42FaZqYht78jQZ2jose9yZFkCj8zyCGWt' + ), amount: [ { timestamp: new Date('2023-01-10T12:00:00.919Z'), @@ -876,110 +1045,131 @@ export const transferWithScheduleEvent = { ], }; -export const contractInitializedEvent = { - tag: 'ContractInitialized', - address: { index: 3132n, subindex: 0n }, +export const contractInitializedEvent: ContractInitializedEvent = { + tag: TransactionEventTag.ContractInitialized, + address: ContractAddress.create(3132), amount: 0n, contractVersion: 1, events: [], - initName: 'init_CIS2-Fractionalizer', + initName: InitName.fromStringUnchecked('init_CIS2-Fractionalizer'), ref: 'e80161061e5074e850dd1fabbabbf80008fc5d3ffae554744aedc4704ee7b412', }; -export const moduleDeployedEvent = { - tag: 'ModuleDeployed', +export const moduleDeployedEvent: ModuleDeployedEvent = { + tag: TransactionEventTag.ModuleDeployed, contents: '3c532ed32dcb3b9f49afb442457a63465987994e400fd5023c8471c26a858ab4', }; -export const delegationRemovedEvent = { - tag: 'DelegationRemoved', - account: '4nvFUvdF3Ki7M6Xc2vHejX7iQW5Gtu7UBu6RaPRZV7LorLToPG', +export const delegationRemovedEvent: DelegationEvent = { + tag: TransactionEventTag.DelegationRemoved, + account: AccountAddress.fromBase58( + '4nvFUvdF3Ki7M6Xc2vHejX7iQW5Gtu7UBu6RaPRZV7LorLToPG' + ), delegatorId: 4002, }; -export const transferWithMemoSummary = { +export const transferWithMemoSummary: BaseAccountTransactionSummary & + TransferWithMemoSummary = { index: 0n, - energyCost: 508n, - hash: '8bfd6c5d3006ea005531d90e88af1075c1a5d0bce1f2befa7abb3ec8b3fb60b5', - type: 'accountTransaction', + energyCost: Energy.create(508), + hash: TransactionHash.fromHexString( + '8bfd6c5d3006ea005531d90e88af1075c1a5d0bce1f2befa7abb3ec8b3fb60b5' + ), + type: TransactionSummaryType.AccountTransaction, cost: 879395n, - sender: '4nJU5pCM49KmrYQ1tsUTEBNBJVxs3X2qo8nKj8CQYsgBmUACHG', - transactionType: 'transferWithMemo', + sender: AccountAddress.fromBase58( + '4nJU5pCM49KmrYQ1tsUTEBNBJVxs3X2qo8nKj8CQYsgBmUACHG' + ), + transactionType: TransactionKindString.TransferWithMemo, transfer: { - tag: 'Transferred', + tag: TransactionEventTag.Transferred, amount: 250000000n, - to: '4fxkFceRT3XyUpb4yW3C2c9RnEBhunyNrKprYarr7htKmMvztG', + to: AccountAddress.fromBase58( + '4fxkFceRT3XyUpb4yW3C2c9RnEBhunyNrKprYarr7htKmMvztG' + ), }, - memo: { tag: 'TransferMemo', memo: '6474657374' }, + memo: { tag: TransactionEventTag.TransferMemo, memo: '6474657374' }, }; -export const upgradedEvent = { - address: { index: 3143n, subindex: 0n }, +export const upgradedEvent: ContractTraceEvent = { + address: ContractAddress.create(3143), from: '7371d1039a0e4587a54b8959eaabf11da83fad24650ee6af380357849648f477', - tag: 'Upgraded', + tag: TransactionEventTag.Upgraded, to: '7371d1039a0e4587a54b8959eaabf11da83fad24650ee6af380357849648f477', }; -export const dataRegisteredEvent = { +export const dataRegisteredEvent: DataRegisteredEvent = { data: '6b68656c6c6f20776f726c64', - tag: 'DataRegistered', + tag: TransactionEventTag.DataRegistered, }; -export const newEncryptedAmountEvent = { - account: '2za2yAXbFiaB151oYqTteZfqiBzibHXizwjNbpdU8hodq9SfEk', +export const newEncryptedAmountEvent: NewEncryptedAmountEvent = { + account: AccountAddress.fromBase58( + '2za2yAXbFiaB151oYqTteZfqiBzibHXizwjNbpdU8hodq9SfEk' + ), encryptedAmount: '8695a917b4404bfa7cb787297662f610f08758f73bc73028a0ec004626b28e28bb82a69e86b9b985e36c588ff2b36089ab40ecae0a199c53f088e6c75012c1c116600dbd22dc33285a22ad63b0a99e5b8b6bad012d1d88568eaddcbac8bf03938762267b06a3353659e436cad83ac2f2b6961ccbf4a77cffaa20757f69f2ef3a2d2c7e9a4bf7c7373e50fbd5da02c46c9565146ac5b56c1a9eb7ae0b9614ed9475e26d4cfc2cb03014f70a4ba82f1aae131b735eec2dcc5ddafe5fac1ab0dbf4', newIndex: 1, - tag: 'NewEncryptedAmount', + tag: TransactionEventTag.NewEncryptedAmount, }; -export const bakerKeysUpdatedEvent = { - account: '4Kmo9keJQaiyAuRM2pRh2xK4e75ph7hp4CzxdFAcRDeQRHfaHT', +export const bakerKeysUpdatedEvent: BakerEvent = { + account: AccountAddress.fromBase58( + '4Kmo9keJQaiyAuRM2pRh2xK4e75ph7hp4CzxdFAcRDeQRHfaHT' + ), aggregationKey: '8cf3c6fe9bebc45e9c9bb34442c5baf7bb612adc193525173d6fe36355be29ad69affeb3937f2b819976ecefeb14c3ae04d9c44d0117eda8c7968602f08f266960226c5fe2014c1bda1794b7fdbd5b5f9d31deb2c053d5f9f3734452e1dcb4b8', bakerId: 15n, electionKey: 'b40185d794485eeb099bdfb7df58fc64fd303847f2a947884648e535b023fe23', signKey: '5cbc1c8ab56047360ff37229760302e03844d48299f4fb1f1247832778f980c0', - tag: 'BakerKeysUpdated', + tag: TransactionEventTag.BakerKeysUpdated, }; -export const bakerStakeIncreasedEvent = { - account: '4JzAXhzJKwG3DGoAbgGhZNnRQqeFdp9zbxv6WUjDbVbyKEie8e', +export const bakerStakeIncreasedEvent: BakerEvent = { + account: AccountAddress.fromBase58( + '4JzAXhzJKwG3DGoAbgGhZNnRQqeFdp9zbxv6WUjDbVbyKEie8e' + ), bakerId: 525n, newStake: 14001000000n, - tag: 'BakerStakeIncreased', + tag: TransactionEventTag.BakerStakeIncreased, }; -export const credentialKeysUpdatedEvent = { +export const credentialKeysUpdatedEvent: CredentialKeysUpdatedEvent = { credId: 'a643d6082a8f80460fff27f3ff27fedbfdc60039527402b8188fc845a849428b5484c82a1589cab7604c1a2be978c39c', - tag: 'CredentialKeysUpdated', + tag: TransactionEventTag.CredentialKeysUpdated, }; -export const credentialsUpdatedEvent = { - account: '3irV7FF3BZbz9ejGTm7EHLUi6CQHdJUELDfyhwkHcLqXmQyUfR', +export const credentialsUpdatedEvent: CredentialsUpdatedEvent = { + account: AccountAddress.fromBase58( + '3irV7FF3BZbz9ejGTm7EHLUi6CQHdJUELDfyhwkHcLqXmQyUfR' + ), newCredIds: [], newThreshold: 1, removedCredIds: [], - tag: 'CredentialsUpdated', + tag: TransactionEventTag.CredentialsUpdated, }; -export const bakerStakeDecreasedEvent = { - tag: 'BakerStakeDecreased', - account: '4Kmo9keJQaiyAuRM2pRh2xK4e75ph7hp4CzxdFAcRDeQRHfaHT', +export const bakerStakeDecreasedEvent: BakerEvent = { + tag: TransactionEventTag.BakerStakeDecreased, + account: AccountAddress.fromBase58( + '4Kmo9keJQaiyAuRM2pRh2xK4e75ph7hp4CzxdFAcRDeQRHfaHT' + ), bakerId: 15n, newStake: 950000000000n, }; -export const delegationStakeDecreasedEvent = { - tag: 'DelegationStakeDecreased', - account: '4mAs6xcFw26fb6u8odkJWoe3fAK8bCJ91BwScUc36DFhh3thwD', +export const delegationStakeDecreasedEvent: DelegationEvent = { + tag: TransactionEventTag.DelegationStakeDecreased, + account: AccountAddress.fromBase58( + '4mAs6xcFw26fb6u8odkJWoe3fAK8bCJ91BwScUc36DFhh3thwD' + ), delegatorId: 57, newStake: 10000000n, }; -export const mintSpecialEvent = { +export const mintSpecialEvent: BlockSpecialEvent = { tag: 'mint', mintBakingReward: 12708081798618n, mintFinalizationReward: 6354040899309n, @@ -1146,12 +1336,14 @@ export const alreadyABakerRejectReason = { tag: 'AlreadyABaker', }; -export const amountTooLargeRejectReason = { - tag: 'AmountTooLarge', +export const amountTooLargeRejectReason: AmountTooLarge = { + tag: RejectReasonTag.AmountTooLarge, contents: { address: { type: 'AddressAccount', - address: '4Qod7UHWmkyz2ahPrWFH1kCqv1cvhT7NtEFbXG7G2soxXSYuMH', + address: AccountAddress.fromBase58( + '4Qod7UHWmkyz2ahPrWFH1kCqv1cvhT7NtEFbXG7G2soxXSYuMH' + ), }, amount: 2000000000n, }, @@ -1200,12 +1392,12 @@ export const invalidInitMethodRejectReason = { export const runtimeFailureRejectReason = { tag: 'RuntimeFailure' }; -export const rejectedReceiveRejectReason = { - contractAddress: { index: 2372n, subindex: 0n }, +export const rejectedReceiveRejectReason: RejectedReceive = { + contractAddress: ContractAddress.create(2372), parameter: '', receiveName: 'auction.finalize', rejectReason: -1, - tag: 'RejectedReceive', + tag: RejectReasonTag.RejectedReceive, }; export const poolClosedRejectReason = { tag: 'PoolClosed' }; @@ -1259,9 +1451,9 @@ export const firstScheduledReleaseExpiredRejectReason = { tag: 'FirstScheduledReleaseExpired', }; -export const invalidContractAddressRejectReason = { - contents: { index: 2339n, subindex: 0n }, - tag: 'InvalidContractAddress', +export const invalidContractAddressRejectReason: InvalidContractAddress = { + contents: ContractAddress.create(2339), + tag: RejectReasonTag.InvalidContractAddress, }; export const missingBakerAddParametersRejectReason = { @@ -1275,8 +1467,8 @@ export const invalidTransferToPublicProofRejectReason = { export const poolWouldBecomeOverDelegatedRejectReason = { tag: 'PoolWouldBecomeOverDelegated', }; -export const bakerAccountInfo = { - accountNonce: 1n, +export const bakerAccountInfo: AccountInfo = { + accountNonce: SequenceNumber.create(1), accountAmount: 7449646704751788n, accountReleaseSchedule: { total: 0n, schedule: [] }, accountCredentials: { @@ -1291,6 +1483,8 @@ export const bakerAccountInfo = { }, }, commitments: { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore cmmAttributes: {}, cmmCredCounter: '80e04147024fd25dcab36e535f990d7678fc22d95d3c8b1456e48b8b208289cc00aae180e718d3800d9efb196dccfa7a', @@ -1325,6 +1519,8 @@ export const bakerAccountInfo = { ipIdentity: 0, policy: { createdAt: '202206', + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore revealedAttributes: {}, validTo: '202306', }, @@ -1344,7 +1540,9 @@ export const bakerAccountInfo = { accountEncryptionKey: 'b14cbfe44a02c6b1f78711176d5f437295367aa4f2a8c2551ee10d25a03adc69d61a332a058971919dad7312e1fc94c5a33426f86d431f2312b19213ced9df3cc97da9111a312aa1abdecef9327388d4936bc61ef6b1f7f0064b6dfc0630bbed', accountIndex: 5n, - accountAddress: '4EJJ1hVhbVZT2sR9xPzWUwFcJWK3fPX54z94zskTozFVk8Xd4L', + accountAddress: AccountAddress.fromBase58( + '4EJJ1hVhbVZT2sR9xPzWUwFcJWK3fPX54z94zskTozFVk8Xd4L' + ), accountBaker: { bakerAggregationVerifyKey: 'b18a02de74826e55f6eadc0f31d0d9a6edfb2993d030e65136f1e1256a69ba523acb40fa4d304d0668aa307c19257a0a10726e70149c904e1ef29aedb2679c825997e3f14edd303bf276f2c0b0c5a4c4870fff0c043150be06b715466be564c4', @@ -1358,7 +1556,7 @@ export const bakerAccountInfo = { transactionCommission: 0.1, }, metadataUrl: '', - openStatus: 'closedForAll', + openStatus: OpenStatusText.ClosedForAll, }, bakerSignatureVerifyKey: 'c385ccb5c8a0710a162f2c107123744650ff35f00040bfa262d974bfb3c3f8f1', @@ -1367,8 +1565,8 @@ export const bakerAccountInfo = { }, }; -export const delegatorAccountInfo = { - accountNonce: 11n, +export const delegatorAccountInfo: AccountInfo = { + accountNonce: SequenceNumber.create(11), accountAmount: 620948501142n, accountReleaseSchedule: { total: 0n, schedule: [] }, accountCredentials: { @@ -1441,6 +1639,8 @@ export const delegatorAccountInfo = { ipIdentity: 0, policy: { createdAt: '202206', + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore revealedAttributes: {}, validTo: '202306', }, @@ -1460,16 +1660,20 @@ export const delegatorAccountInfo = { accountEncryptionKey: 'b14cbfe44a02c6b1f78711176d5f437295367aa4f2a8c2551ee10d25a03adc69d61a332a058971919dad7312e1fc94c5af9816eae1ab8c733e26e790a7d88c5688472dcd8b536668b0d2182e406321499695ae80c8363505a479ffd89daf5fbb', accountIndex: 276n, - accountAddress: '3bFo43GiPnkk5MmaSdsRVboaX2DNSKaRkLseQbyB3WPW1osPwh', + accountAddress: AccountAddress.fromBase58( + '3bFo43GiPnkk5MmaSdsRVboaX2DNSKaRkLseQbyB3WPW1osPwh' + ), accountDelegation: { - delegationTarget: { delegateType: 'Passive' }, + delegationTarget: { + delegateType: DelegationTargetType.PassiveDelegation, + }, restakeEarnings: true, stakedAmount: 620942412516n, }, }; -export const credIdAccountInfo = { - accountNonce: 19n, +export const credIdAccountInfo: AccountInfo = { + accountNonce: SequenceNumber.create(19), accountAmount: 35495453082577742n, accountReleaseSchedule: { total: 0n, schedule: [] }, accountCredentials: { @@ -1484,6 +1688,8 @@ export const credIdAccountInfo = { }, }, commitments: { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore cmmAttributes: {}, cmmCredCounter: 'b0aa65f420a9f3fab61d3f875eebcc221e43154bfaf1b6365dace99bff20778de7003437631222e845fd9917c8d2874b', @@ -1518,6 +1724,8 @@ export const credIdAccountInfo = { ipIdentity: 0, policy: { createdAt: '202206', + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore revealedAttributes: {}, validTo: '202306', }, @@ -1537,11 +1745,13 @@ export const credIdAccountInfo = { accountEncryptionKey: 'b14cbfe44a02c6b1f78711176d5f437295367aa4f2a8c2551ee10d25a03adc69d61a332a058971919dad7312e1fc94c5aa730045bcd20bb5c24349db29d949f767e72f7cce459dc163c4b93c780a7d7f65801dda8ff7e4fc06fdf1a1b246276f', accountIndex: 11n, - accountAddress: '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G', + accountAddress: AccountAddress.fromBase58( + '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G' + ), }; -export const regularAccountInfo = { - accountNonce: 19n, +export const regularAccountInfo: AccountInfo = { + accountNonce: SequenceNumber.create(19), accountAmount: 35495453082577742n, accountReleaseSchedule: { total: 0n, schedule: [] }, accountCredentials: { @@ -1556,6 +1766,8 @@ export const regularAccountInfo = { }, }, commitments: { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore cmmAttributes: {}, cmmCredCounter: 'b0aa65f420a9f3fab61d3f875eebcc221e43154bfaf1b6365dace99bff20778de7003437631222e845fd9917c8d2874b', @@ -1590,6 +1802,8 @@ export const regularAccountInfo = { ipIdentity: 0, policy: { createdAt: '202206', + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore revealedAttributes: {}, validTo: '202306', }, @@ -1609,7 +1823,9 @@ export const regularAccountInfo = { accountEncryptionKey: 'b14cbfe44a02c6b1f78711176d5f437295367aa4f2a8c2551ee10d25a03adc69d61a332a058971919dad7312e1fc94c5aa730045bcd20bb5c24349db29d949f767e72f7cce459dc163c4b93c780a7d7f65801dda8ff7e4fc06fdf1a1b246276f', accountIndex: 11n, - accountAddress: '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G', + accountAddress: AccountAddress.fromBase58( + '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G' + ), }; const rootKeys = { @@ -1742,7 +1958,9 @@ export const chainParameters: ChainParametersV1 = { denominator: 7989497115n, }, accountCreationLimit: 10, - foundationAccount: '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G', + foundationAccount: AccountAddress.fromBase58( + '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G' + ), mintPerPayday: 0.000261157877, rewardPeriodLength: 24n, delegatorCooldown: 1209600n, @@ -1913,7 +2131,9 @@ export const oldChainParameters: ChainParametersV0 = { euroPerEnergy: { numerator: 1n, denominator: 50000n }, microGTUPerEuro: { numerator: 50000000n, denominator: 1n }, accountCreationLimit: 10, - foundationAccount: '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G', + foundationAccount: AccountAddress.fromBase58( + '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G' + ), bakerCooldownEpochs: 166n, minimumThresholdForBaking: 15000000000n, rewardParameters: { @@ -1935,15 +2155,17 @@ export const oldChainParameters: ChainParametersV0 = { rootKeys, }; -export const bakerPoolStatus = { - poolType: 'BakerPool', +export const bakerPoolStatus: BakerPoolStatus = { + poolType: PoolStatusType.BakerPool, bakerId: 1n, - bakerAddress: '3U4sfVSqGG6XK8g6eho2qRYtnHc4MWJBG1dfxdtPGbfHwFxini', + bakerAddress: AccountAddress.fromBase58( + '3U4sfVSqGG6XK8g6eho2qRYtnHc4MWJBG1dfxdtPGbfHwFxini' + ), bakerEquityCapital: 7347853372468927n, delegatedCapital: 0n, delegatedCapitalCap: 0n, poolInfo: { - openStatus: 'openForAll', + openStatus: OpenStatusText.OpenForAll, metadataUrl: '', commissionRates: { transactionCommission: 0.1, @@ -1951,7 +2173,9 @@ export const bakerPoolStatus = { finalizationCommission: 1, }, }, - bakerStakePendingChange: { pendingChangeType: 'NoChange' }, + bakerStakePendingChange: { + pendingChangeType: BakerPoolPendingChangeType.NoChange, + }, currentPaydayStatus: { blocksBaked: 1329n, finalizationLive: true, @@ -1977,15 +2201,17 @@ export const passiveDelegationStatus = { allPoolTotalCapital: 46071942529284135n, }; -export const bakerPoolStatusWithPendingChange = { - poolType: 'BakerPool', +export const bakerPoolStatusWithPendingChange: BakerPoolStatus = { + poolType: PoolStatusType.BakerPool, bakerId: 1879n, - bakerAddress: '4aCoaW3qkQRnY3fUGThQcEMGSPLUEQ7XL9Yagx2UR91QpvtoAe', + bakerAddress: AccountAddress.fromBase58( + '4aCoaW3qkQRnY3fUGThQcEMGSPLUEQ7XL9Yagx2UR91QpvtoAe' + ), bakerEquityCapital: 19999999999n, delegatedCapital: 0n, delegatedCapitalCap: 39999999998n, poolInfo: { - openStatus: 'openForAll', + openStatus: OpenStatusText.OpenForAll, metadataUrl: 'b', commissionRates: { transactionCommission: 0.1, @@ -1994,47 +2220,52 @@ export const bakerPoolStatusWithPendingChange = { }, }, bakerStakePendingChange: { - pendingChangeType: 'RemovePool', + pendingChangeType: BakerPoolPendingChangeType.RemovePool, effectiveTime: new Date('2022-12-08T07:54:00.000Z'), }, currentPaydayStatus: null, allPoolTotalCapital: 46470271917743628n, }; -export const invokeContractResult = { +export const invokeContractResult: InvokeContractResult = { tag: 'success', - usedEnergy: 502n, - returnValue: '000f17697d00000000', + usedEnergy: Energy.create(502), + returnValue: ReturnValue.fromHexString('000f17697d00000000'), events: [ { - tag: 'Updated', + tag: TransactionEventTag.Updated, contractVersion: 1, - address: { index: 81n, subindex: 0n }, + address: ContractAddress.create(81), instigator: { type: 'AddressAccount', - address: '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G', + address: AccountAddress.fromBase58( + '3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G' + ), }, amount: 0n, - message: '', - receiveName: 'PiggyBank.view', + message: Parameter.empty(), + receiveName: ReceiveName.fromStringUnchecked('PiggyBank.view'), events: [], }, ], }; -export const blocksAtHeight = [ +export const blocksAtHeight: BlockHash.Type[] = [ '99ceb0dfcd36714d9c141fde08e85da1d0d624994e95b35114f14193c811b76e', -]; +].map(BlockHash.fromHexString); export const blockInfo: BlockInfoV0 = { - blockParent: - '28d92ec42dbda119f0b0207d3400b0573fe8baf4b0d3dbe44b86781ad6b655cf', - blockHash: - 'fe88ff35454079c3df11d8ae13d5777babd61f28be58494efe51b6593e30716e', + blockParent: BlockHash.fromHexString( + '28d92ec42dbda119f0b0207d3400b0573fe8baf4b0d3dbe44b86781ad6b655cf' + ), + blockHash: BlockHash.fromHexString( + 'fe88ff35454079c3df11d8ae13d5777babd61f28be58494efe51b6593e30716e' + ), blockStateHash: '6e602157d76677fc4b630b2701571d2b0166e2b08e0afe8ab92356e4d0b88a6a', - blockLastFinalized: - '28d92ec42dbda119f0b0207d3400b0573fe8baf4b0d3dbe44b86781ad6b655cf', + blockLastFinalized: BlockHash.fromHexString( + '28d92ec42dbda119f0b0207d3400b0573fe8baf4b0d3dbe44b86781ad6b655cf' + ), blockHeight: 1259179n, blockBaker: 4n, blockSlot: 50801674n, diff --git a/packages/nodejs/test/specialEvents.test.ts b/packages/nodejs/test/specialEvents.test.ts index c010ce80e..76307470d 100644 --- a/packages/nodejs/test/specialEvents.test.ts +++ b/packages/nodejs/test/specialEvents.test.ts @@ -1,12 +1,13 @@ -import { streamToList } from '@concordium/common-sdk'; +import { streamToList, BlockHash } from '@concordium/common-sdk'; import * as expected from './resources/expectedJsons.js'; import { getNodeClientV2 as getNodeClient } from './testHelpers.js'; const client = getNodeClient(); test('mint', async () => { - const blockHash = - '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a'; + const blockHash = BlockHash.fromHexString( + '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a' + ); const eventStream = client.getBlockSpecialEvents(blockHash); const events = await streamToList(eventStream); @@ -14,8 +15,9 @@ test('mint', async () => { }); test('paydayFoundationReward', async () => { - const blockHash = - '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a'; + const blockHash = BlockHash.fromHexString( + '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a' + ); const eventStream = client.getBlockSpecialEvents(blockHash); const events = await streamToList(eventStream); @@ -23,8 +25,9 @@ test('paydayFoundationReward', async () => { }); test('paydayPoolReward', async () => { - const blockHash = - '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a'; + const blockHash = BlockHash.fromHexString( + '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a' + ); const eventStream = client.getBlockSpecialEvents(blockHash); const events = await streamToList(eventStream); @@ -32,8 +35,9 @@ test('paydayPoolReward', async () => { }); test('paydayAccountReward', async () => { - const blockHash = - '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a'; + const blockHash = BlockHash.fromHexString( + '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a' + ); const eventStream = client.getBlockSpecialEvents(blockHash); const events = await streamToList(eventStream); @@ -41,8 +45,9 @@ test('paydayAccountReward', async () => { }); test('blockAccrueReward', async () => { - const blockHash = - '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a'; + const blockHash = BlockHash.fromHexString( + '4031d210b35a3fb9f13d1ce6e5c621abd9a26a2de54b71fc19bfb55fe17cce6a' + ); const eventStream = client.getBlockSpecialEvents(blockHash); const events = await streamToList(eventStream); @@ -50,8 +55,9 @@ test('blockAccrueReward', async () => { }); test('bakingRewards', async () => { - const blockHash = - 'da7a5401049c8ee0de0b6c66ab4f6167ef770b332df9dd9979ec2c553d1a18dd'; + const blockHash = BlockHash.fromHexString( + 'da7a5401049c8ee0de0b6c66ab4f6167ef770b332df9dd9979ec2c553d1a18dd' + ); const eventStream = client.getBlockSpecialEvents(blockHash); const events = await streamToList(eventStream); @@ -59,8 +65,9 @@ test('bakingRewards', async () => { }); test('finalizationRewards', async () => { - const blockHash = - 'da7a5401049c8ee0de0b6c66ab4f6167ef770b332df9dd9979ec2c553d1a18dd'; + const blockHash = BlockHash.fromHexString( + 'da7a5401049c8ee0de0b6c66ab4f6167ef770b332df9dd9979ec2c553d1a18dd' + ); const eventStream = client.getBlockSpecialEvents(blockHash); const events = await streamToList(eventStream); @@ -68,8 +75,9 @@ test('finalizationRewards', async () => { }); test('blockReward', async () => { - const blockHash = - 'da7a5401049c8ee0de0b6c66ab4f6167ef770b332df9dd9979ec2c553d1a18dd'; + const blockHash = BlockHash.fromHexString( + 'da7a5401049c8ee0de0b6c66ab4f6167ef770b332df9dd9979ec2c553d1a18dd' + ); const eventStream = client.getBlockSpecialEvents(blockHash); const events = await streamToList(eventStream); diff --git a/packages/nodejs/test/testHelpers.ts b/packages/nodejs/test/testHelpers.ts index 2e4c2f290..449b7a429 100644 --- a/packages/nodejs/test/testHelpers.ts +++ b/packages/nodejs/test/testHelpers.ts @@ -1,7 +1,11 @@ /* eslint-disable import/no-extraneous-dependencies */ import * as fs from 'fs'; import { credentials } from '@grpc/grpc-js'; -import { IdentityInput } from '@concordium/common-sdk'; +import { + AccountAddress, + ContractAddress, + IdentityInput, +} from '@concordium/common-sdk'; import { ConcordiumGRPCClient } from '@concordium/common-sdk/grpc'; import { decryptMobileWalletExport, @@ -97,3 +101,64 @@ export function getIdentityInput(): IdentityInput { }; return identityInput; } + +type OverrideCheck = { + when: (a: unknown) => boolean; + check: (l: A, r: A) => boolean; +}; + +const checkBuffers: OverrideCheck = { + when(u) { + return u instanceof ArrayBuffer; + }, + check(l, r) { + if (l.byteLength !== r.byteLength) { + return false; + } + const lu8 = new Uint8Array(l); + const ru8 = new Uint8Array(r); + for (let i = 0; i < l.byteLength; i++) { + if (lu8.at(i) !== ru8.at(i)) { + return false; + } + } + return true; + }, +}; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const equalOverrides: OverrideCheck[] = [ + { + when: AccountAddress.isAccountAddress, + check: AccountAddress.equals, + }, + { when: ContractAddress.isContractAddress, check: ContractAddress.equals }, + checkBuffers, +]; + +export function expectToEqual(value: A, expected: A) { + const override = equalOverrides.find(({ when: guard }) => guard(expected)); + if (override !== undefined) { + if (!override.when(value)) { + throw new Error(`Expected: ${expected} instead got ${value}`); + } + expect(override.check(value, expected)).toBeTruthy(); + } else if (Array.isArray(expected)) { + if (!Array.isArray(value) || value.length !== expected.length) { + throw new Error(`Expected: ${expected} instead got ${value}`); + } + for (let i = 0; i < expected.length; i++) { + expectToEqual(value[i], expected[i]); + } + } else if (typeof expected === 'object' && expected !== null) { + for (const key of Object.keys(expected)) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + expectToEqual(value[key], expected[key]); + } + } else { + if (value !== expected) { + expect(value).toBe(expected); + } + } +}