Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"@types/chai-as-promised": "^7.1.5",
"@types/eventsource": "^1.1.15",
"@types/humanize-duration": "^3.18.1",
"@types/lodash": "^4.14.191",
"@types/mocha": "^5.2.7",
"@types/node": "^14.14.31",
"@types/node-fetch": "^2.6.4",
Expand Down Expand Up @@ -170,7 +169,6 @@
"eventsource": "^2.0.2",
"glob": "^7.1.6",
"humanize-duration": "^3.24.0",
"lodash": "^4.17.21",
"node-fetch": "2.6.13",
"reflect-metadata": "^0.1.13",
"ts-results": "npm:@casperlabs/ts-results@^3.3.4",
Expand Down
58 changes: 58 additions & 0 deletions src/tests/types/TransactionTarget.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { expect } from 'chai';

import {
Args,
ContractHash,
ExecutableDeployItem,
StoredVersionedContractByHash,
StoredVersionedContractByName,
TransactionTarget
} from '../../types';

describe('TransactionTarget', () => {
it('ignores null version for stored versioned contract by hash', () => {
const session = new ExecutableDeployItem();
session.storedVersionedContractByHash = new StoredVersionedContractByHash(
ContractHash.fromJSON(
'hash-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
),
'mint',
Args.fromMap({})
);
(session.storedVersionedContractByHash as any).version = null;

const target = TransactionTarget.newTransactionTargetFromSession(session);

expect(target.stored?.id.byPackageHash?.version).to.equal(undefined);
});

it('keeps numeric version for stored versioned contract by hash', () => {
const session = new ExecutableDeployItem();
session.storedVersionedContractByHash = new StoredVersionedContractByHash(
ContractHash.fromJSON(
'hash-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
),
'mint',
Args.fromMap({}),
7
);

const target = TransactionTarget.newTransactionTargetFromSession(session);

expect(target.stored?.id.byPackageHash?.version).to.equal(7);
});

it('ignores null version for stored versioned contract by name', () => {
const session = new ExecutableDeployItem();
session.storedVersionedContractByName = new StoredVersionedContractByName(
'cep78',
'mint',
Args.fromMap({})
);
(session.storedVersionedContractByName as any).version = null;

const target = TransactionTarget.newTransactionTargetFromSession(session);

expect(target.stored?.id.byPackageName?.version).to.equal(undefined);
});
});
2 changes: 1 addition & 1 deletion src/types/TransactionTarget.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import isNull from 'lodash/isNull.js';
import { BigNumber } from '@ethersproject/bignumber';
import { concat } from '@ethersproject/bytes';

Expand All @@ -18,6 +17,7 @@ import {
byteArrayJsonDeserializer,
byteArrayJsonSerializer
} from './SerializationUtils';
import { isNull } from '../utils';

/**
* Represents a runtime environment for Casper transactions.
Expand Down
2 changes: 2 additions & 0 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export const arrayEquals = (a: Uint8Array, b: Uint8Array): boolean => {
*/
export const sleep = (ms: number): Promise<void> =>
new Promise(resolve => setTimeout(resolve, ms));

export const isNull = (value: unknown): value is null => value === null;
Loading