Skip to content
4 changes: 4 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Added

- deserialize function for DeployModulePayload implemented instead of throwing an exception of not supporting deserialize

## 11.0.0

### Fixed
Expand Down
17 changes: 15 additions & 2 deletions packages/sdk/src/accountTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,21 @@ export class DeployModuleHandler implements AccountTransactionHandler<DeployModu
}
}

deserialize(): DeployModulePayload {
throw new Error('deserialize not supported');
deserialize(serializePayload: Cursor): DeployModulePayload {
const moduleVersion = serializePayload.read(4); // version
const moduleLength = serializePayload.read(4)?.readUInt32BE(0); // length
const moduleSource = serializePayload.read(moduleLength); // wasm module

if (moduleVersion) {
return {
source: new Uint8Array(moduleSource),
version: moduleVersion.readUInt32BE(0),
};
} else {
return {
source: new Uint8Array(moduleSource),
};
}
}

toJSON(payload: DeployModulePayload): DeployModulePayloadJSON {
Expand Down
9 changes: 9 additions & 0 deletions packages/sdk/test/ci/deserialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CcdAmount,
ContractAddress,
DataBlob,
DeployModulePayload,
RegisterDataPayload,
SequenceNumber,
SimpleTransferPayload,
Expand Down Expand Up @@ -80,6 +81,14 @@ test('test deserialize registerData ', () => {
deserializeAccountTransactionBase(AccountTransactionType.RegisterData, payload);
});

test('test deserialize DeployModule ', () => {
const payload: DeployModulePayload = {
version: 1,
source: new Uint8Array([0x00, 0xab, 0x53, 0x03, 0x92, 0x68, 0x10, 0xee]),
};
deserializeAccountTransactionBase(AccountTransactionType.DeployModule, payload);
});

test('Expired transactions can be deserialized', () => {
const payload: SimpleTransferPayload = {
amount: CcdAmount.fromMicroCcd(5100000),
Expand Down