Skip to content

Commit d3baef1

Browse files
committed
[wip] Adapt e2e tests to the new foundry-rpc
1 parent a5b749b commit d3baef1

File tree

10 files changed

+250
-272
lines changed

10 files changed

+250
-272
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": "^2.0.0-alpha.2",
5151
"codechain-stakeholder-sdk": "https://github.com/majecty/codechain-stakeholder-sdk-js#v2.0.0-alpha.1",
5252
"elliptic": "^6.4.1",
53+
"foundry-rpc": "github:MSNTCS/foundry-rpc-js#alpha",
5354
"lodash": "^4.17.11",
5455
"mkdirp": "^0.5.1",
5556
"ncp": "^2.0.0",

test/src/e2e/account.test.ts

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ 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"})).not.to.be.null;
37+
expect(await node.rpc.account.create({passphrase : "my-password"})).not.to.be.null;
3938
});
4039

4140
describe("importRaw", function() {
@@ -53,26 +52,26 @@ describe("account", function() {
5352
{ networkId: "tc" }
5453
);
5554
expect(
56-
await node.sdk.rpc.account.importRaw(randomSecret)
55+
await node.rpc.account.importRaw( {secret: "0x".concat(randomSecret), passphrase:""})
5756
).to.equal(address.toString());
5857
});
5958

6059
it("KeyError", async function() {
6160
try {
62-
await node.sdk.rpc.account.importRaw(invalidSecret);
61+
await node.rpc.account.importRaw({secret: "0x".concat(invalidSecret), passphrase:""});
6362
expect.fail();
6463
} catch (e) {
65-
expect(e).is.similarTo(ERROR.KEY_ERROR);
64+
expect(e.toString()).is.include(ERROR.KEY_ERROR);
6665
}
6766
});
6867

6968
it("AlreadyExists", async function() {
7069
try {
71-
await node.sdk.rpc.account.importRaw(randomSecret);
72-
await node.sdk.rpc.account.importRaw(randomSecret);
70+
await node.rpc.account.importRaw({secret: "0x".concat(randomSecret), passphrase:null});
71+
await node.rpc.account.importRaw({secret: "0x".concat(randomSecret), passphrase:null});
7372
expect.fail();
7473
} catch (e) {
75-
expect(e).is.similarTo(ERROR.ALREADY_EXISTS);
74+
expect(e.toString()).is.include(ERROR.ALREADY_EXISTS);
7675
}
7776
});
7877
});
@@ -84,9 +83,9 @@ describe("account", function() {
8483
let secret: string;
8584
beforeEach(async function() {
8685
secret = node.sdk.util.generatePrivateKey();
87-
address = await node.sdk.rpc.account.importRaw(
88-
secret,
89-
"my-password"
86+
address = await node.rpc.account.importRaw({
87+
secret:"0x".concat(secret),
88+
passphrase: "my-password"}
9089
);
9190
});
9291

@@ -95,107 +94,98 @@ describe("account", function() {
9594
message,
9695
secret
9796
);
98-
const signature = await node.sdk.rpc.account.sign(
97+
const signature = await node.rpc.account.sign({
9998
message,
100-
address,
101-
"my-password"
99+
account: address,
100+
passphrase: "my-password"}
102101
);
103102
expect(signature).to.equal(`0x${calculatedSignature}`);
104103
});
105104

106105
it("WrongPassword", async function() {
107106
try {
108-
await node.sdk.rpc.account.sign(
109-
message,
110-
address,
111-
"wrong-password"
107+
await node.rpc.account.sign(
108+
{
109+
message,
110+
account: "0x".concat(address),
111+
passphrase: "wrong-password"}
112112
);
113113
expect.fail();
114114
} catch (e) {
115-
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
115+
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
116116
}
117117
});
118118

119119
it("NoSuchAccount", async function() {
120120
try {
121-
await node.sdk.rpc.account.sign(
121+
await node.rpc.account.sign({
122122
message,
123-
invalidAddress,
124-
"my-password"
123+
account: invalidAddress,
124+
passphrase: "my-password"}
125125
);
126126
expect.fail();
127127
} catch (e) {
128-
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
128+
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
129129
}
130130
});
131131
});
132132

133133
describe("unlock", function() {
134134
let address: string;
135135
beforeEach(async function() {
136-
address = await node.sdk.rpc.account.create("123");
136+
address = await node.rpc.account.create({passphrase: "123"});
137137
});
138138

139139
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);
140+
await node.rpc.account.unlock({account: address, passphrase :"123"});
141+
await node.rpc.account.unlock({account:address, passphrase:"123", duration:0});
142+
await node.rpc.account.unlock({account: address, passphrase:"123", duration: 300});
143143
});
144144

145145
it("WrongPassword", async function() {
146146
try {
147-
await node.sdk.rpc.account.unlock(address, "456");
147+
await node.rpc.account.unlock({account:address, passphrase: "456"});
148148
expect.fail();
149149
} catch (e) {
150-
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
150+
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
151151
}
152152
});
153153

154154
it("NoSuchAccount", async function() {
155155
try {
156-
await node.sdk.rpc.account.unlock(invalidAddress, "456");
156+
await node.rpc.account.unlock({account :invalidAddress.toString(), passphrase :"456"});
157157
expect.fail();
158158
} catch (e) {
159-
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
159+
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
160160
}
161161
});
162162
});
163163

164164
describe("changePassword", function() {
165165
let address: string;
166166
beforeEach(async function() {
167-
address = await node.sdk.rpc.account.create("123");
167+
address = await node.rpc.account.create({passphrase: "123"});
168168
});
169169

170170
it("Ok", async function() {
171-
await node.sdk.rpc.sendRpcRequest("account_changePassword", [
172-
address,
173-
"123",
174-
"456"
175-
]);
171+
await node.rpc.account.changePassword({account: address, oldPassphrase: "123", newPassphrase: "456"});
176172
});
177173

178174
it("WrongPassword", async function() {
179175
try {
180-
await node.sdk.rpc.sendRpcRequest(
181-
"account_changePassword",
182-
[address, "456", "123"]
183-
);
176+
await node.rpc.account.changePassword({account: address, oldPassphrase: "456", newPassphrase: "123"});
184177
expect.fail();
185178
} catch (e) {
186-
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
179+
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
187180
}
188181
});
189182

190183
it("NoSuchAccount", async function() {
191184
try {
192-
await node.sdk.rpc.sendRpcRequest(
193-
"account_changePassword",
194-
[invalidAddress, "123", "345"]
195-
);
185+
await node.rpc.account.changePassword({account:invalidAddress, oldPassphrase: "123", newPassphrase:"345" });
196186
expect.fail();
197187
} catch (e) {
198-
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
188+
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
199189
}
200190
});
201191
});
@@ -210,4 +200,4 @@ describe("account", function() {
210200
await node.clean();
211201
});
212202
});
213-
});
203+
});

0 commit comments

Comments
 (0)