Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Merge #112
Browse files Browse the repository at this point in the history
112: SDK v1.0.20 - Buffer to Uint8Array fix r=zie1ony a=zie1ony

## SDK 1.0.20

### Fixed

- Deserialize `Deploy.hash` to `Uint8Array` instead of `Buffer`.

### Which JIRA ticket does this PR relate to?

https://casperlabs.atlassian.net/browse/DEV-27

Co-authored-by: Maciej Zielinski <maciek.s.zielinski@gmail.com>
  • Loading branch information
bors[bot] and zie1ony authored Feb 11, 2021
2 parents f0b8f8a + 5959b31 commit f836e5b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 46 deletions.
14 changes: 10 additions & 4 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ All notable changes to casper-client-sdk.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.19]
## 1.0.20

### Fixed

- Deserialize `Deploy.hash` to `Uint8Array` instead of `Buffer`.

## 1.0.19

### Added

Expand All @@ -14,7 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- BytesArrayValue's fromBytes.

## [1.0.18]
## 1.0.18

### Added

Expand All @@ -24,7 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Deploy's body hash derivation.

## [1.0.17]
## 1.0.17

### Added

Expand All @@ -35,7 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Default `gasPrice` changed from `10` to `1`.
- Casper balances checks return `BigNumber` now.

## [1.0.15]
## 1.0.15

### Added

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "casper-client-sdk",
"version": "1.0.19",
"version": "1.0.20",
"license": "Apache 2.0",
"description": "SDK to interact with the Casper blockchain",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/lib/Conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export function encodeBase16(bytes: Uint8Array): string {
* @param base16String base16 encoded string
*/
export function decodeBase16(base16String: string): Uint8Array {
return Buffer.from(base16String, 'hex');
return new Uint8Array(Buffer.from(base16String, 'hex'));
}
4 changes: 3 additions & 1 deletion packages/sdk/src/lib/DeployUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const byteArrayJsonSerializer: (bytes: Uint8Array) => string = (
return encodeBase16(bytes);
};

const byteArrayJsonDeserializer: (str: string) => ByteArray = (str: string) => {
const byteArrayJsonDeserializer: (str: string) => Uint8Array = (
str: string
) => {
return decodeBase16(str);
};

Expand Down
35 changes: 10 additions & 25 deletions packages/sdk/test/lib/DeployUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Keys, DeployUtil, CLValue } from '../../src/lib';
import { TypedJSON } from 'typedjson';

describe('DeployUtil', () => {
it('should stringify/parse DeployHeader correctly', function() {
it('should stringify/parse DeployHeader correctly', function () {
const ed25519Key = Keys.Ed25519.new();
const deployHeader = new DeployUtil.DeployHeader(
ed25519Key.publicKey,
Expand All @@ -20,7 +20,7 @@ describe('DeployUtil', () => {
expect(deployHeader1).to.deep.equal(deployHeader);
});

it('should allow to extract data from Transfer', function() {
it('should allow to extract data from Transfer', function () {
const senderKey = Keys.Ed25519.new();
const recipientKey = Keys.Ed25519.new();
const networkName = 'test-network';
Expand Down Expand Up @@ -53,17 +53,11 @@ describe('DeployUtil', () => {
assert.isTrue(deploy.isStandardPayment());
assert.deepEqual(deploy.header.account, senderKey.publicKey);
assert.deepEqual(
deploy.payment
.getArgByName('amount')!
.asBigNumber()
.toNumber(),
deploy.payment.getArgByName('amount')!.asBigNumber().toNumber(),
paymentAmount
);
assert.deepEqual(
deploy.session
.getArgByName('amount')!
.asBigNumber()
.toNumber(),
deploy.session.getArgByName('amount')!.asBigNumber().toNumber(),
transferAmount
);
assert.deepEqual(
Expand All @@ -83,7 +77,7 @@ describe('DeployUtil', () => {
assert.deepEqual(deploy.approvals[1].signer, recipientKey.accountHex());
});

it('should allow to add arg to Deploy', function() {
it('should allow to add arg to Deploy', function () {
const senderKey = Keys.Ed25519.new();
const recipientKey = Keys.Ed25519.new();
const networkName = 'test-network';
Expand Down Expand Up @@ -117,27 +111,18 @@ describe('DeployUtil', () => {
deploy = DeployUtil.deployFromJson(json)!;

assert.deepEqual(
deploy.session
.getArgByName('custom_id')!
.asBigNumber()
.toNumber(),
deploy.session.getArgByName('custom_id')!.asBigNumber().toNumber(),
customId
);
assert.isTrue(deploy.isTransfer());
assert.isTrue(deploy.isStandardPayment());
assert.deepEqual(deploy.header.account, senderKey.publicKey);
assert.deepEqual(
deploy.payment
.getArgByName('amount')!
.asBigNumber()
.toNumber(),
deploy.payment.getArgByName('amount')!.asBigNumber().toNumber(),
paymentAmount
);
assert.deepEqual(
deploy.session
.getArgByName('amount')!
.asBigNumber()
.toNumber(),
deploy.session.getArgByName('amount')!.asBigNumber().toNumber(),
transferAmount
);
assert.deepEqual(
Expand All @@ -158,7 +143,7 @@ describe('DeployUtil', () => {
assert.notEqual(oldDeploy.header.bodyHash, deploy.header.bodyHash);
});

it('should not allow to add arg to a signed Deploy', function() {
it('should not allow to add arg to a signed Deploy', function () {
const senderKey = Keys.Ed25519.new();
const recipientKey = Keys.Ed25519.new();
const networkName = 'test-network';
Expand Down Expand Up @@ -187,7 +172,7 @@ describe('DeployUtil', () => {
}).to.throw('Can not add argument to already signed deploy.');
});

it('should allow to extract additional args from Transfer.', function() {
it('should allow to extract additional args from Transfer.', function () {
const from = Keys.Ed25519.new();
const to = Keys.Ed25519.new();
const networkName = 'test-network';
Expand Down
17 changes: 3 additions & 14 deletions packages/sdk/test/lib/RuntimeArgs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ describe(`RuntimeArgs`, () => {
let str = serializer.stringify(value);
let parsed = serializer.parse(str)!;
assert.deepEqual(
value
.asOption()
.getSome()
.asBigNumber(),
parsed
.asOption()
.getSome()
.asBigNumber()
value.asOption().getSome().asBigNumber(),
parsed.asOption().getSome().asBigNumber()
);
});

Expand All @@ -80,12 +74,7 @@ describe(`RuntimeArgs`, () => {
let serializer = new TypedJSON(RuntimeArgs);
let str = serializer.stringify(runtimeArgs);
let value = serializer.parse(str)!;
assert.isTrue(
value.args
.get('a')!
.asOption()
.isNone()
);
assert.isTrue(value.args.get('a')!.asOption().isNone());
});

it('should allow to extract lists of account hashes.', () => {
Expand Down

0 comments on commit f836e5b

Please sign in to comment.