Skip to content

Adapt e2e tests to the new foundry-rpc #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2020
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
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"codechain-sdk": "https://github.com/junha1/codechain-sdk-js#test2.0.1",
"codechain-stakeholder-sdk": "https://github.com/junha1/codechain-stakeholder-sdk-js#master",
"elliptic": "^6.4.1",
"foundry-rpc": "git://github.com/CodeChain-io/foundry-rpc-js.git#alpha",
"lodash": "^4.17.11",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
Expand Down
142 changes: 87 additions & 55 deletions test/src/e2e/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ describe("account", function() {
});

it("getList", async function() {
expect(await node.sdk.rpc.account.getList()).not.to.be.null;
expect(await node.rpc.account.getList()).not.to.be.null;
});

it("create", async function() {
expect(await node.sdk.rpc.account.create()).not.to.be.null;
expect(await node.sdk.rpc.account.create("my-password")).not.to.be
.null;
expect(await node.rpc.account.create({ passphrase: "my-password" }))
.not.to.be.null;
expect(await node.rpc.account.create({ passphrase: "my-password" }))
.not.to.be.null;
});

describe("importRaw", function() {
Expand All @@ -53,26 +54,38 @@ describe("account", function() {
{ networkId: "tc" }
);
expect(
await node.sdk.rpc.account.importRaw(randomSecret)
await node.rpc.account.importRaw({
secret: "0x".concat(randomSecret),
passphrase: ""
})
).to.equal(address.toString());
});

it("KeyError", async function() {
try {
await node.sdk.rpc.account.importRaw(invalidSecret);
await node.rpc.account.importRaw({
secret: "0x".concat(invalidSecret),
passphrase: ""
});
expect.fail();
} catch (e) {
expect(e).is.similarTo(ERROR.KEY_ERROR);
expect(e.toString()).is.include(ERROR.KEY_ERROR);
}
});

it("AlreadyExists", async function() {
try {
await node.sdk.rpc.account.importRaw(randomSecret);
await node.sdk.rpc.account.importRaw(randomSecret);
await node.rpc.account.importRaw({
secret: "0x".concat(randomSecret),
passphrase: null
});
await node.rpc.account.importRaw({
secret: "0x".concat(randomSecret),
passphrase: null
});
expect.fail();
} catch (e) {
expect(e).is.similarTo(ERROR.ALREADY_EXISTS);
expect(e.toString()).is.include(ERROR.ALREADY_EXISTS);
}
});
});
Expand All @@ -84,118 +97,137 @@ describe("account", function() {
let secret: string;
beforeEach(async function() {
secret = node.sdk.util.generatePrivateKey();
address = await node.sdk.rpc.account.importRaw(
secret,
"my-password"
);
address = await node.rpc.account.importRaw({
secret: "0x".concat(secret),
passphrase: "my-password"
});
});

it("Ok", async function() {
const calculatedSignature = node.sdk.util.signEcdsa(
message,
secret
);
const signature = await node.sdk.rpc.account.sign(
message,
address,
"my-password"
);
const signature = await node.rpc.account.sign({
message: `0x${message}`,
account: address,
passphrase: "my-password"
});
expect(signature).to.equal(`0x${calculatedSignature}`);
});

it("WrongPassword", async function() {
try {
await node.sdk.rpc.account.sign(
message,
address,
"wrong-password"
);
await node.rpc.account.sign({
message: `0x${message}`,
account: address,
passphrase: "wrong-password"
});
expect.fail();
} catch (e) {
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
}
});

it("NoSuchAccount", async function() {
try {
await node.sdk.rpc.account.sign(
message,
invalidAddress,
"my-password"
);
await node.rpc.account.sign({
message: `0x${message}`,
account: invalidAddress,
passphrase: "my-password"
});
expect.fail();
} catch (e) {
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
}
});
});

describe("unlock", function() {
let address: string;
beforeEach(async function() {
address = await node.sdk.rpc.account.create("123");
address = await node.rpc.account.create({ passphrase: "123" });
});

it("Ok", async function() {
await node.sdk.rpc.account.unlock(address, "123");
await node.sdk.rpc.account.unlock(address, "123", 0);
await node.sdk.rpc.account.unlock(address, "123", 300);
await node.rpc.account.unlock({
account: address,
passphrase: "123"
});
await node.rpc.account.unlock({
account: address,
passphrase: "123",
duration: 0
});
await node.rpc.account.unlock({
account: address,
passphrase: "123",
duration: 300
});
});

it("WrongPassword", async function() {
try {
await node.sdk.rpc.account.unlock(address, "456");
await node.rpc.account.unlock({
account: address,
passphrase: "456"
});
expect.fail();
} catch (e) {
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
}
});

it("NoSuchAccount", async function() {
try {
await node.sdk.rpc.account.unlock(invalidAddress, "456");
await node.rpc.account.unlock({
account: invalidAddress.toString(),
passphrase: "456"
});
expect.fail();
} catch (e) {
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
}
});
});

describe("changePassword", function() {
let address: string;
beforeEach(async function() {
address = await node.sdk.rpc.account.create("123");
address = await node.rpc.account.create({ passphrase: "123" });
});

it("Ok", async function() {
await node.sdk.rpc.sendRpcRequest("account_changePassword", [
address,
"123",
"456"
]);
await node.rpc.account.changePassword({
account: address,
oldPassphrase: "123",
newPassphrase: "456"
});
});

it("WrongPassword", async function() {
try {
await node.sdk.rpc.sendRpcRequest(
"account_changePassword",
[address, "456", "123"]
);
await node.rpc.account.changePassword({
account: address,
oldPassphrase: "456",
newPassphrase: "123"
});
expect.fail();
} catch (e) {
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
}
});

it("NoSuchAccount", async function() {
try {
await node.sdk.rpc.sendRpcRequest(
"account_changePassword",
[invalidAddress, "123", "345"]
);
await node.rpc.account.changePassword({
account: invalidAddress,
oldPassphrase: "123",
newPassphrase: "345"
});
expect.fail();
} catch (e) {
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
}
});
});
Expand Down
9 changes: 4 additions & 5 deletions test/src/e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { expect } from "chai";
import "mocha";
import CodeChain from "../helper/spawn";
import { log } from "util";

describe("solo - 1 node", function() {
let node: CodeChain;
Expand All @@ -26,19 +27,17 @@ describe("solo - 1 node", function() {
});

it("ping", async function() {
expect(await node.sdk.rpc.node.ping()).to.equal("pong");
expect(await node.rpc.ping()).to.contain("pong");
});

it("getNodeVersion", async function() {
expect(await node.sdk.rpc.node.getNodeVersion()).to.match(
expect(await node.rpc.version()).to.match(
/^[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9.]*)?$/
);
});

it("getCommitHash", async function() {
expect(await node.sdk.rpc.node.getCommitHash()).to.match(
/^[a-fA-F0-9]{40}$/
);
expect(await node.rpc.commitHash()).to.match(/^[a-fA-F0-9]{40}$/);
});

afterEach(function() {
Expand Down
Loading