Skip to content

Commit

Permalink
fix(core): info action proposal procedure serialization and de-serial…
Browse files Browse the repository at this point in the history
…ization
  • Loading branch information
iccicci committed Mar 6, 2024
1 parent f85fb55 commit baebef7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { CborReader, CborWriter } from '../../CBOR';
import { GovernanceActionKind } from './GovernanceActionKind';
import { HexBlob, InvalidArgumentError } from '@cardano-sdk/util';

const EMBEDDED_GROUP_SIZE = 1;

/**
* Represents an action that has no direct effect on the blockchain,
* but serves as an on-chain record or informative notice.
Expand All @@ -22,6 +24,7 @@ export class InfoAction {

// CDDL
// info_action = 6
writer.writeStartArray(EMBEDDED_GROUP_SIZE);
writer.writeInt(GovernanceActionKind.Info);
return writer.encodeAsHex();
}
Expand All @@ -35,6 +38,14 @@ export class InfoAction {
static fromCbor(cbor: HexBlob): InfoAction {
const reader = new CborReader(cbor);

const length = reader.readStartArray();

if (length !== EMBEDDED_GROUP_SIZE)
throw new InvalidArgumentError(
'cbor',
`Expected an array of ${EMBEDDED_GROUP_SIZE} elements, but got an array of ${length} elements`
);

const kind = Number(reader.readUInt());

if (kind !== GovernanceActionKind.Info)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Cardano from '../../../Cardano';
import { Anchor } from '../../Common/Anchor';
import { CborReader, CborReaderState, CborWriter } from '../../CBOR';
import { CborReader, CborWriter } from '../../CBOR';
import { GovernanceActionKind } from './GovernanceActionKind';
import { HardForkInitiationAction } from './HardForkInitiationAction';
import { HexBlob, InvalidStateError } from '@cardano-sdk/util';
Expand Down Expand Up @@ -116,15 +116,10 @@ export class ProposalProcedure {

const actionReader = new CborReader(actionCbor);

let kind;
let action;
actionReader.readStartArray();

if (actionReader.peekState() === CborReaderState.UnsignedInteger) {
kind = Number(actionReader.readInt());
} else {
actionReader.readStartArray();
kind = Number(actionReader.readInt());
}
let action;
const kind = Number(actionReader.readInt());

switch (kind) {
case GovernanceActionKind.ParameterChange:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HexBlob } from '@cardano-sdk/util';
import { InfoAction } from '../../../../src/Serialization';

// Test data used in the following tests was generated with the cardano-serialization-lib
const cbor = HexBlob('06');
const cbor = HexBlob('8106');
const core = {
__typename: Cardano.GovernanceActionType.info_action
} as Cardano.InfoAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HexBlob } from '@cardano-sdk/util';
import { ProposalProcedure } from '../../../../src/Serialization';

const infoActionCbor = HexBlob(
'841a000f4240581de1cb0ec2692497b458e46812c8a5bfa2931d1a2d965a99893828ec810f06827668747470733a2f2f7777772e736f6d6575726c2e696f58200000000000000000000000000000000000000000000000000000000000000000'
'841a000f4240581de1cb0ec2692497b458e46812c8a5bfa2931d1a2d965a99893828ec810f8106827668747470733a2f2f7777772e736f6d6575726c2e696f58200000000000000000000000000000000000000000000000000000000000000000'
);

const infoActionCore = {
Expand Down

0 comments on commit baebef7

Please sign in to comment.