Skip to content

Commit

Permalink
Fixed PendingUpdate type (#292)
Browse files Browse the repository at this point in the history
* Fixed `PendingUpdate` type
  • Loading branch information
rasmus-kirk authored Oct 19, 2023
1 parent 81a6312 commit 7cdeb90
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Several types have been replaced with a module containing the type itself togeth
- Removed `JsonRpcClient` and types and functionality associated solely with this class.
- Renamed `AccountSequenceNumber` module to `SequenceNumber`.
- Fix type for `TranferredEvent` from `ContractTraceEvent` to only be from contract addresses to account addresses.
- Added `effectiveTime` field to `PendingUpdate`.

### Added

Expand Down
9 changes: 9 additions & 0 deletions packages/sdk/src/grpc/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,15 @@ function trMintDistributionCpv1Update(
export function pendingUpdate(
pendingUpdate: v2.PendingUpdate
): v1.PendingUpdate {
return {
effectiveTime: Timestamp.fromProto(unwrap(pendingUpdate.effectiveTime)),
effect: trPendingUpdateEffect(pendingUpdate),
};
}

export function trPendingUpdateEffect(
pendingUpdate: v2.PendingUpdate
): v1.PendingUpdateEffect {
const effect = pendingUpdate.effect;
switch (effect.oneofKind) {
case 'protocol':
Expand Down
13 changes: 11 additions & 2 deletions packages/sdk/src/types/chainUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
import type * as Energy from './Energy.js';
import type * as Duration from './Duration.js';
import type * as CcdAmount from './CcdAmount.js';
import { Timestamp } from '../Timestamp.js';

type ChainUpdate<UpdateType, T> = {
/** The type of the update */
Expand Down Expand Up @@ -184,8 +185,16 @@ export type CommonUpdate =
/** A union of chain updates */
export type UpdateInstructionPayload = CommonUpdate | RootUpdate | Level1Update;

/** A union of possible pending updates */
export type PendingUpdate =
/** A pending update */
export type PendingUpdate = {
/** The effective time of the update */
effectiveTime: Timestamp.Type;
/** The effect of the update */
effect: PendingUpdateEffect;
};

/** A union of possible effects */
export type PendingUpdateEffect =
| CommonUpdate
| PendingHigherLevelKeyUpdate
| PendingAuthorizationKeysUpdate;
Expand Down
6 changes: 5 additions & 1 deletion packages/sdk/test/client/clientV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,11 @@ test.each([clientV2, clientWeb])('getBlockPendingUpdates', async (client) => {
client.getBlockPendingUpdates(pendingUpdateBlock);
const pendingUpdateList = await streamToList(pendingUpdateStream);

expect(pendingUpdateList).toEqual(expected.pendingUpdateList);
expect(pendingUpdateList.length).toEqual(1);
expect(pendingUpdateList[0].effectiveTime.value).toEqual(
expected.pendingUpdate.effectiveTime.value
);
expect(pendingUpdateList[0].effect).toEqual(expected.pendingUpdate.effect);
});

test.each([clientV2, clientWeb])(
Expand Down
8 changes: 5 additions & 3 deletions packages/sdk/test/client/resources/expectedJsons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
ReturnValue,
SequenceNumber,
StakePendingChangeType,
Timestamp,
TransactionEventTag,
TransactionHash,
TransactionKindString,
Expand Down Expand Up @@ -626,8 +627,9 @@ export const specialEventList: BlockSpecialEvent[] = [
},
];

export const pendingUpdateList: PendingUpdate[] = [
{
export const pendingUpdate: PendingUpdate = {
effectiveTime: Timestamp.fromMillis(1669115100n),
effect: {
updateType: UpdateType.Protocol,
update: {
message: 'Enable protocol version 5',
Expand All @@ -638,7 +640,7 @@ export const pendingUpdateList: PendingUpdate[] = [
specificationAuxiliaryData: '',
},
},
];
};

export const blockFinalizationSummary: BlockFinalizationSummary = {
tag: 'record',
Expand Down

0 comments on commit 7cdeb90

Please sign in to comment.