Skip to content

Commit

Permalink
fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffmannjan committed Jun 24, 2024
1 parent 39b06ab commit 99fb286
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/lib/ByteConverters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Keys,
AccessRights,
decodeBase16,
Hash
KeyHashAddr
} from '..';
import { toBytesNumber, toBytesDeployHash } from './ByteConverters';

Expand Down Expand Up @@ -182,7 +182,7 @@ describe(`numbers' toBytes`, () => {

expect(bytes).to.deep.eq(validBytes);

const uref = CLURef.fromFormattedStr(
const uref = CLURef.fromFormattedString(
'uref-d93dfedfc13180a0ea188841e64e0a1af718a733216e7fae4909dface372d2b0-007'
);
const clVal2 = CLValueBuilder.key(uref);
Expand Down Expand Up @@ -241,7 +241,7 @@ describe(`numbers' toBytes`, () => {

it('should serialize/deserialize Hash variant of Key correctly', () => {
const keyHash = CLValueBuilder.key(
new Hash(Uint8Array.from(Array(32).fill(42)))
new KeyHashAddr(Uint8Array.from(Array(32).fill(42)))
);
// prettier-ignore
const expectedBytes = Uint8Array.from([
Expand Down Expand Up @@ -314,7 +314,7 @@ describe(`numbers' toBytes`, () => {
});

it('should serialize/deserialize URef correctly', () => {
const uref = CLURef.fromFormattedStr(
const uref = CLURef.fromFormattedString(
'uref-ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-007'
);
// prettier-ignore
Expand Down
8 changes: 4 additions & 4 deletions src/lib/CLValue/AccountHash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CLValueParsers, CLAccountHashType } from './index';

describe('CLAccountHash', () => {
it('Should be able to return proper value by calling .value()', () => {
const arr8 = new Uint8Array([21, 31]);
const arr8 = new Uint8Array(32);
const myHash = new CLAccountHash(arr8);

expect(myHash.value()).to.be.deep.eq(arr8);
Expand All @@ -28,12 +28,12 @@ describe('CLAccountHash', () => {
const hashStr =
'account-hash-9fb3803b335f14b083b97400e57d5c8e8ad0ec5859a51225b6611e34357c8d77';

const fromStr = CLAccountHash.fromFormattedStr(hashStr);
const fromStr = CLAccountHash.fromFormattedString(hashStr);

expect(fromStr.toFormattedStr()).to.eq(hashStr);
expect(fromStr.toFormattedString()).to.eq(hashStr);

const badFn = () =>
CLAccountHash.fromFormattedStr(
CLAccountHash.fromFormattedString(
'9fb3803b335f14b083b97400e57d5c8e8ad0ec5859a51225b6611e34357c8d77'
);
expect(badFn).to.throw();
Expand Down
14 changes: 7 additions & 7 deletions src/lib/CLValue/Key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CLURef,
AccessRights,
CLAccountHash,
Hash
KeyHashAddr
} from './index';
import { decodeBase16 } from '../Conversions';

Expand All @@ -15,7 +15,7 @@ describe('CLKey', () => {
'2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a';

it('Create with (CLByteArray) and test .value() / isHash()', () => {
const byteArr = new Hash(new Uint8Array([21, 31]));
const byteArr = new KeyHashAddr(new Uint8Array([21, 31]));
const myKey = new CLKey(byteArr)

expect(myKey.value()).to.be.deep.eq(byteArr);
Expand All @@ -33,7 +33,7 @@ describe('CLKey', () => {
});

it('Create with (CLAccountHash) and test .value() isAccount()', () => {
const arr8 = new Uint8Array([21, 31]);
const arr8 = new Uint8Array(32);
const myHash = new CLAccountHash(arr8);
const myKey = new CLKey(myHash);
expect(myKey.value()).to.deep.eq(myHash);
Expand All @@ -42,7 +42,7 @@ describe('CLKey', () => {

it('toBytes() / fromBytes() with CLByteArray', () => {
const arr8 = Uint8Array.from(Array(32).fill(42));
const byteArr = new Hash(arr8);
const byteArr = new KeyHashAddr(arr8);
const expectedBytes = Uint8Array.from([
1,
42,
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('CLKey', () => {
});

it('toJSON() / fromJSON() with CLByteArray', () => {
const byteArr = new Hash(new Uint8Array([21, 31]));
const byteArr = new KeyHashAddr(new Uint8Array([21, 31]));
const myKey = new CLKey(byteArr);
const json = CLValueParsers.toJSON(myKey).unwrap();
const expectedJson = JSON.parse('{"bytes":"01151f","cl_type":"Key"}');
Expand Down Expand Up @@ -169,11 +169,11 @@ describe('CLKey', () => {
it('toBytes() with invalid data', () => {
// @ts-ignore
const badFn = () => CLValueParsers.toBytes(new CLKey([1, 2, 3]));
expect(badFn).to.throw('Unknown byte types');
expect(badFn).to.throw();
});

it('Should be able to return proper value by calling .clType()', () => {
const arr8 = new Hash(new Uint8Array([21, 31]));
const arr8 = new KeyHashAddr(new Uint8Array([21, 31]));
const myKey = new CLKey(arr8);

expect(myKey.clType().toString()).to.be.eq('Key');
Expand Down
4 changes: 2 additions & 2 deletions src/lib/CLValue/List.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CLI32,
CLI32Type,
CLKey,
Hash,
KeyHashAddr,
} from './index';

describe('CLValue List implementation', () => {
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('CLValue List implementation', () => {

it('Runs toJSON() / fromJSON() properly', () => {
const clKey = new CLKey(
new Hash(
new KeyHashAddr(
Uint8Array.from([
48,
17,
Expand Down
10 changes: 5 additions & 5 deletions src/lib/CLValue/URef.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ describe('CLUref', () => {
});
});

it('fromFormattedStr() / toFormattedStr() proper value', () => {
const myURef = CLURef.fromFormattedStr(formattedStr);
const badFn1 = () => CLURef.fromFormattedStr('xxxx-ttttttttttttttt-000');
const badFn2 = () => CLURef.fromFormattedStr('uref-ttttttttttttttt');
it('fromFormattedString() / toFormattedString() proper value', () => {
const myURef = CLURef.fromFormattedString(formattedStr);
const badFn1 = () => CLURef.fromFormattedString('xxxx-ttttttttttttttt-000');
const badFn2 = () => CLURef.fromFormattedString('uref-ttttttttttttttt');

expect(myURef).to.be.an.instanceof(CLURef);
expect(myURef.toFormattedStr()).to.be.eq(formattedStr);
expect(myURef.toFormattedString()).to.be.eq(formattedStr);
expect(badFn1).to.throw("Prefix is not 'uref-");
expect(badFn2).to.throw('No access rights as suffix');
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/InitiatorAddr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class InitiatorAddr {
public toJSON(): unknown {
if (this.AccountHash) {
return {
AccountHash: this.AccountHash.toFormattedStr()
AccountHash: this.AccountHash.toFormattedString()
};
} else if (this.PublicKey) {
return {
Expand All @@ -68,7 +68,7 @@ export const matchInitiatorAddress = (json: any): InitiatorAddr | undefined => {
return InitiatorAddr.fromPublicKey(CLPublicKey.fromHex(json.PublicKey));
} else if (json.AccountHash) {
return InitiatorAddr.fromAccountHash(
CLAccountHash.fromFormattedStr(json.AccountHash)
CLAccountHash.fromFormattedString(json.AccountHash)
);
}
return undefined;
Expand Down

0 comments on commit 99fb286

Please sign in to comment.