Skip to content

Commit 027bc13

Browse files
MSNTCSmajecty
authored andcommitted
Adapt e2e tests to the new foundry-rpc
1 parent aba1ae9 commit 027bc13

21 files changed

+1386
-795
lines changed

test/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"codechain-sdk": "https://github.com/junha1/codechain-sdk-js#test2.0.1",
5151
"codechain-stakeholder-sdk": "https://github.com/junha1/codechain-stakeholder-sdk-js#master",
5252
"elliptic": "^6.4.1",
53+
"foundry-rpc": "git://github.com/CodeChain-io/foundry-rpc-js.git#alpha",
5354
"lodash": "^4.17.11",
5455
"mkdirp": "^0.5.1",
5556
"ncp": "^2.0.0",

test/src/e2e/account.test.ts

Lines changed: 87 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ describe("account", function() {
2929
});
3030

3131
it("getList", async function() {
32-
expect(await node.sdk.rpc.account.getList()).not.to.be.null;
32+
expect(await node.rpc.account.getList()).not.to.be.null;
3333
});
3434

3535
it("create", async function() {
36-
expect(await node.sdk.rpc.account.create()).not.to.be.null;
37-
expect(await node.sdk.rpc.account.create("my-password")).not.to.be
38-
.null;
36+
expect(await node.rpc.account.create({ passphrase: "my-password" }))
37+
.not.to.be.null;
38+
expect(await node.rpc.account.create({ passphrase: "my-password" }))
39+
.not.to.be.null;
3940
});
4041

4142
describe("importRaw", function() {
@@ -53,26 +54,38 @@ describe("account", function() {
5354
{ networkId: "tc" }
5455
);
5556
expect(
56-
await node.sdk.rpc.account.importRaw(randomSecret)
57+
await node.rpc.account.importRaw({
58+
secret: "0x".concat(randomSecret),
59+
passphrase: ""
60+
})
5761
).to.equal(address.toString());
5862
});
5963

6064
it("KeyError", async function() {
6165
try {
62-
await node.sdk.rpc.account.importRaw(invalidSecret);
66+
await node.rpc.account.importRaw({
67+
secret: "0x".concat(invalidSecret),
68+
passphrase: ""
69+
});
6370
expect.fail();
6471
} catch (e) {
65-
expect(e).is.similarTo(ERROR.KEY_ERROR);
72+
expect(e.toString()).is.include(ERROR.KEY_ERROR);
6673
}
6774
});
6875

6976
it("AlreadyExists", async function() {
7077
try {
71-
await node.sdk.rpc.account.importRaw(randomSecret);
72-
await node.sdk.rpc.account.importRaw(randomSecret);
78+
await node.rpc.account.importRaw({
79+
secret: "0x".concat(randomSecret),
80+
passphrase: null
81+
});
82+
await node.rpc.account.importRaw({
83+
secret: "0x".concat(randomSecret),
84+
passphrase: null
85+
});
7386
expect.fail();
7487
} catch (e) {
75-
expect(e).is.similarTo(ERROR.ALREADY_EXISTS);
88+
expect(e.toString()).is.include(ERROR.ALREADY_EXISTS);
7689
}
7790
});
7891
});
@@ -84,118 +97,137 @@ describe("account", function() {
8497
let secret: string;
8598
beforeEach(async function() {
8699
secret = node.sdk.util.generatePrivateKey();
87-
address = await node.sdk.rpc.account.importRaw(
88-
secret,
89-
"my-password"
90-
);
100+
address = await node.rpc.account.importRaw({
101+
secret: "0x".concat(secret),
102+
passphrase: "my-password"
103+
});
91104
});
92105

93106
it("Ok", async function() {
94107
const calculatedSignature = node.sdk.util.signEcdsa(
95108
message,
96109
secret
97110
);
98-
const signature = await node.sdk.rpc.account.sign(
99-
message,
100-
address,
101-
"my-password"
102-
);
111+
const signature = await node.rpc.account.sign({
112+
message: `0x${message}`,
113+
account: address,
114+
passphrase: "my-password"
115+
});
103116
expect(signature).to.equal(`0x${calculatedSignature}`);
104117
});
105118

106119
it("WrongPassword", async function() {
107120
try {
108-
await node.sdk.rpc.account.sign(
109-
message,
110-
address,
111-
"wrong-password"
112-
);
121+
await node.rpc.account.sign({
122+
message: `0x${message}`,
123+
account: address,
124+
passphrase: "wrong-password"
125+
});
113126
expect.fail();
114127
} catch (e) {
115-
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
128+
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
116129
}
117130
});
118131

119132
it("NoSuchAccount", async function() {
120133
try {
121-
await node.sdk.rpc.account.sign(
122-
message,
123-
invalidAddress,
124-
"my-password"
125-
);
134+
await node.rpc.account.sign({
135+
message: `0x${message}`,
136+
account: invalidAddress,
137+
passphrase: "my-password"
138+
});
126139
expect.fail();
127140
} catch (e) {
128-
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
141+
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
129142
}
130143
});
131144
});
132145

133146
describe("unlock", function() {
134147
let address: string;
135148
beforeEach(async function() {
136-
address = await node.sdk.rpc.account.create("123");
149+
address = await node.rpc.account.create({ passphrase: "123" });
137150
});
138151

139152
it("Ok", async function() {
140-
await node.sdk.rpc.account.unlock(address, "123");
141-
await node.sdk.rpc.account.unlock(address, "123", 0);
142-
await node.sdk.rpc.account.unlock(address, "123", 300);
153+
await node.rpc.account.unlock({
154+
account: address,
155+
passphrase: "123"
156+
});
157+
await node.rpc.account.unlock({
158+
account: address,
159+
passphrase: "123",
160+
duration: 0
161+
});
162+
await node.rpc.account.unlock({
163+
account: address,
164+
passphrase: "123",
165+
duration: 300
166+
});
143167
});
144168

145169
it("WrongPassword", async function() {
146170
try {
147-
await node.sdk.rpc.account.unlock(address, "456");
171+
await node.rpc.account.unlock({
172+
account: address,
173+
passphrase: "456"
174+
});
148175
expect.fail();
149176
} catch (e) {
150-
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
177+
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
151178
}
152179
});
153180

154181
it("NoSuchAccount", async function() {
155182
try {
156-
await node.sdk.rpc.account.unlock(invalidAddress, "456");
183+
await node.rpc.account.unlock({
184+
account: invalidAddress.toString(),
185+
passphrase: "456"
186+
});
157187
expect.fail();
158188
} catch (e) {
159-
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
189+
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
160190
}
161191
});
162192
});
163193

164194
describe("changePassword", function() {
165195
let address: string;
166196
beforeEach(async function() {
167-
address = await node.sdk.rpc.account.create("123");
197+
address = await node.rpc.account.create({ passphrase: "123" });
168198
});
169199

170200
it("Ok", async function() {
171-
await node.sdk.rpc.sendRpcRequest("account_changePassword", [
172-
address,
173-
"123",
174-
"456"
175-
]);
201+
await node.rpc.account.changePassword({
202+
account: address,
203+
oldPassphrase: "123",
204+
newPassphrase: "456"
205+
});
176206
});
177207

178208
it("WrongPassword", async function() {
179209
try {
180-
await node.sdk.rpc.sendRpcRequest(
181-
"account_changePassword",
182-
[address, "456", "123"]
183-
);
210+
await node.rpc.account.changePassword({
211+
account: address,
212+
oldPassphrase: "456",
213+
newPassphrase: "123"
214+
});
184215
expect.fail();
185216
} catch (e) {
186-
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
217+
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
187218
}
188219
});
189220

190221
it("NoSuchAccount", async function() {
191222
try {
192-
await node.sdk.rpc.sendRpcRequest(
193-
"account_changePassword",
194-
[invalidAddress, "123", "345"]
195-
);
223+
await node.rpc.account.changePassword({
224+
account: invalidAddress,
225+
oldPassphrase: "123",
226+
newPassphrase: "345"
227+
});
196228
expect.fail();
197229
} catch (e) {
198-
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
230+
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
199231
}
200232
});
201233
});

test/src/e2e/basic.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { expect } from "chai";
1818
import "mocha";
1919
import CodeChain from "../helper/spawn";
20+
import { log } from "util";
2021

2122
describe("solo - 1 node", function() {
2223
let node: CodeChain;
@@ -26,19 +27,17 @@ describe("solo - 1 node", function() {
2627
});
2728

2829
it("ping", async function() {
29-
expect(await node.sdk.rpc.node.ping()).to.equal("pong");
30+
expect(await node.rpc.ping()).to.contain("pong");
3031
});
3132

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

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

4443
afterEach(function() {

0 commit comments

Comments
 (0)