Skip to content

Commit 49012bd

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

File tree

10 files changed

+1524
-347
lines changed

10 files changed

+1524
-347
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#v2.0.0-alpha.1",
5354
"lodash": "^4.17.11",
5455
"mkdirp": "^0.5.1",
5556
"ncp": "^2.0.0",

test/src/e2e/account.test.ts

Lines changed: 39 additions & 47 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,100 @@ describe("account", function() {
9594
message,
9695
secret
9796
);
97+
9898
const signature = await node.sdk.rpc.account.sign(
9999
message,
100100
address,
101101
"my-password"
102102
);
103+
103104
expect(signature).to.equal(`0x${calculatedSignature}`);
104105
});
105106

106107
it("WrongPassword", async function() {
107108
try {
108-
await node.sdk.rpc.account.sign(
109-
message,
110-
address,
111-
"wrong-password"
109+
await node.rpc.account.sign(
110+
{
111+
message,
112+
account: "0x".concat(address),
113+
passphrase: "wrong-password"}
112114
);
113115
expect.fail();
114116
} catch (e) {
115-
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
117+
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
116118
}
117119
});
118120

119121
it("NoSuchAccount", async function() {
120122
try {
121-
await node.sdk.rpc.account.sign(
123+
await node.rpc.account.sign({
122124
message,
123-
invalidAddress,
124-
"my-password"
125+
account: invalidAddress,
126+
passphrase: "my-password"}
125127
);
126128
expect.fail();
127129
} catch (e) {
128-
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
130+
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
129131
}
130132
});
131133
});
132134

133135
describe("unlock", function() {
134136
let address: string;
135137
beforeEach(async function() {
136-
address = await node.sdk.rpc.account.create("123");
138+
address = await node.rpc.account.create({passphrase: "123"});
137139
});
138140

139141
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);
142+
await node.rpc.account.unlock({account: address, passphrase :"123"});
143+
await node.rpc.account.unlock({account:address, passphrase:"123", duration:0});
144+
await node.rpc.account.unlock({account: address, passphrase:"123", duration: 300});
143145
});
144146

145147
it("WrongPassword", async function() {
146148
try {
147-
await node.sdk.rpc.account.unlock(address, "456");
149+
await node.rpc.account.unlock({account:address, passphrase: "456"});
148150
expect.fail();
149151
} catch (e) {
150-
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
152+
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
151153
}
152154
});
153155

154156
it("NoSuchAccount", async function() {
155157
try {
156-
await node.sdk.rpc.account.unlock(invalidAddress, "456");
158+
await node.rpc.account.unlock({account :invalidAddress.toString(), passphrase :"456"});
157159
expect.fail();
158160
} catch (e) {
159-
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
161+
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
160162
}
161163
});
162164
});
163165

164166
describe("changePassword", function() {
165167
let address: string;
166168
beforeEach(async function() {
167-
address = await node.sdk.rpc.account.create("123");
169+
address = await node.rpc.account.create({passphrase: "123"});
168170
});
169171

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

178176
it("WrongPassword", async function() {
179177
try {
180-
await node.sdk.rpc.sendRpcRequest(
181-
"account_changePassword",
182-
[address, "456", "123"]
183-
);
178+
await node.rpc.account.changePassword({account: address, oldPassphrase: "456", newPassphrase: "123"});
184179
expect.fail();
185180
} catch (e) {
186-
expect(e).is.similarTo(ERROR.WRONG_PASSWORD);
181+
expect(e.toString()).is.include(ERROR.WRONG_PASSWORD);
187182
}
188183
});
189184

190185
it("NoSuchAccount", async function() {
191186
try {
192-
await node.sdk.rpc.sendRpcRequest(
193-
"account_changePassword",
194-
[invalidAddress, "123", "345"]
195-
);
187+
await node.rpc.account.changePassword({account:invalidAddress, oldPassphrase: "123", newPassphrase:"345" });
196188
expect.fail();
197189
} catch (e) {
198-
expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT);
190+
expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT);
199191
}
200192
});
201193
});
@@ -210,4 +202,4 @@ describe("account", function() {
210202
await node.clean();
211203
});
212204
});
213-
});
205+
});

0 commit comments

Comments
 (0)