Skip to content

Commit

Permalink
fix(packaging): update of nats.ws package to latest version
Browse files Browse the repository at this point in the history
nats.ws is updated due to frequent error: InvalidStateError: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state. Latest version is expected to reduce/eliminate this error
  • Loading branch information
Passerino committed Sep 21, 2021
1 parent 5696431 commit d739480
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 64 deletions.
45 changes: 37 additions & 8 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -77,7 +77,7 @@
"ethers": "^5.4.4",
"js-sha3": "^0.8.0",
"lodash.difference": "^4.5.0",
"nats.ws": "1.0.0-111",
"nats.ws": "^1.3.0",
"qs": "^6.9.4",
"tslib": "^2.0.3",
"uuid": "^7.0.3"
Expand Down
87 changes: 45 additions & 42 deletions test/application.testSuite.ts
Expand Up @@ -8,59 +8,62 @@ import { Keys } from "@ew-did-registry/keys";
const { namehash } = utils;

export const appsTests = () => {
const app = "app1";
const appNode = `${app}.${ENSNamespaceTypes.Application}.${org1}.${root}`;
const app = "app1";
const appNode = `${app}.${ENSNamespaceTypes.Application}.${org1}.${root}`;

test("application can be created", async () => {
const appDefinition = { appName: "Application 1" };
await rootOwnerIam.createApplication({
appName: app,
data: appDefinition,
namespace: `${ENSNamespaceTypes.Application}.${org1}.${root}`
});
test("application can be created", async () => {
const appDefinition = { appName: "Application 1" };
await rootOwnerIam.createApplication({
appName: app,
data: appDefinition,
namespace: `${ENSNamespaceTypes.Application}.${org1}.${root}`,
});

expect(await rootOwnerIam.checkExistenceOfDomain({ domain: appNode })).toBe(true);
expect(
await rootOwnerIam.checkExistenceOfDomain({ domain: `${ENSNamespaceTypes.Roles}.${appNode}` })
).toBe(true);
expect(await ensResolver.name(namehash(appNode))).toBe(appNode);
expect(
await rootOwnerIam.getSubdomains({ domain: `${ENSNamespaceTypes.Application}.${org1}.${root}` })
).toContain(`${app}.${ENSNamespaceTypes.Application}.${org1}.${root}`);
expect(await rootOwnerIam.checkExistenceOfDomain({ domain: appNode })).toBe(true);
expect(await rootOwnerIam.checkExistenceOfDomain({ domain: `${ENSNamespaceTypes.Roles}.${appNode}` })).toBe(
true,
);
expect(await ensResolver.name(namehash(appNode))).toBe(appNode);
expect(
await rootOwnerIam.getSubdomains({ domain: `${ENSNamespaceTypes.Application}.${org1}.${root}` }),
).toContain(`${app}.${ENSNamespaceTypes.Application}.${org1}.${root}`);

const readAppDefinition = await rootOwnerIam.getDefinition({ type: ENSNamespaceTypes.Application, namespace: appNode });
expect(readAppDefinition).toMatchObject(appDefinition);
});
const readAppDefinition = await rootOwnerIam.getDefinition({
type: ENSNamespaceTypes.Application,
namespace: appNode,
});
expect(readAppDefinition).toMatchObject(appDefinition);
});

test("application owner can be changed", async () => {
const newOwner = new Keys();
await replenish(newOwner.getAddress());
const newOwnerIam = await createIam(newOwner.privateKey);
test("application owner can be changed", async () => {
const newOwner = new Keys();
await replenish(newOwner.getAddress());
const newOwnerIam = await createIam(newOwner.privateKey);

expect(await rootOwnerIam.isOwner({ domain: appNode, user: rootOwner.address }));
expect(await rootOwnerIam.isOwner({ domain: appNode, user: rootOwner.address }));

await rootOwnerIam.changeAppOwnership({
namespace: appNode,
newOwner: newOwner.getAddress()
});
await rootOwnerIam.changeAppOwnership({
namespace: appNode,
newOwner: newOwner.getAddress(),
});

expect(await rootOwnerIam.isOwner({ domain: appNode, user: newOwner.getAddress() }));
expect(await rootOwnerIam.isOwner({ domain: appNode, user: newOwner.getAddress() }));

await newOwnerIam.changeAppOwnership({
namespace: appNode,
newOwner: rootOwner.address
await newOwnerIam.changeAppOwnership({
namespace: appNode,
newOwner: rootOwner.address,
});

expect(await rootOwnerIam.isOwner({ domain: appNode, user: rootOwner.address }));
});

expect(await rootOwnerIam.isOwner({ domain: appNode, user: rootOwner.address }));
});
test("application can be deleted", async () => {
expect(await rootOwnerIam.checkExistenceOfDomain({ domain: appNode })).toBe(true);

test("application can be deleted", async () => {
expect(await rootOwnerIam.checkExistenceOfDomain({ domain: appNode })).toBe(true);
await rootOwnerIam.deleteApplication({
namespace: appNode,
});

await rootOwnerIam.deleteApplication({
namespace: appNode
expect(await rootOwnerIam.checkExistenceOfDomain({ domain: appNode })).toBe(false);
});

expect(await rootOwnerIam.checkExistenceOfDomain({ domain: appNode })).toBe(false);
});
};
20 changes: 9 additions & 11 deletions test/initializeConnection.testSuite.ts
Expand Up @@ -6,16 +6,14 @@ import { WalletProvider } from "../src/types/WalletProvider";
const iam_withoutKey = new IAM({ rpcUrl });

export const initializeConnectionTests = () => {
test("initializeConnection requires privateKey or walletProvider enum", async () => {
await expect(iam_withoutKey.initializeConnection()).rejects.toThrow(
ERROR_MESSAGES.WALLET_TYPE_NOT_PROVIDED
);
});
test("initializeConnection requires privateKey or walletProvider enum", async () => {
await expect(iam_withoutKey.initializeConnection()).rejects.toThrow(ERROR_MESSAGES.WALLET_TYPE_NOT_PROVIDED);
});

test("initializeConnection requires walletProvider to be known value", async () => {
// Typescript only checks on transpilation, need to verify error is thrown if unsupported value is passed in.
await expect(
iam_withoutKey.initializeConnection({ walletProvider: "not_a_provider" as WalletProvider })
).rejects.toThrow(ERROR_MESSAGES.WALLET_PROVIDER_NOT_SUPPORTED);
});
test("initializeConnection requires walletProvider to be known value", async () => {
// Typescript only checks on transpilation, need to verify error is thrown if unsupported value is passed in.
await expect(
iam_withoutKey.initializeConnection({ walletProvider: "not_a_provider" as WalletProvider }),
).rejects.toThrow(ERROR_MESSAGES.WALLET_PROVIDER_NOT_SUPPORTED);
});
};
4 changes: 2 additions & 2 deletions test/testUtils/mocks.ts
Expand Up @@ -48,9 +48,9 @@ export const restoreCacheClient = () => {
};

let _jsonCodec;
export const mockJsonCodec = () => {
export const mockJsonCodec = <T = any>() => {
({ _jsonCodec } = Reflect.get(IAM, "prototype"));
const jsonCodec = JSONCodec();
const jsonCodec = JSONCodec<T>();
Reflect.set(IAM.prototype, "_jsonCodec", jsonCodec);
return jsonCodec;
};
Expand Down

0 comments on commit d739480

Please sign in to comment.