Skip to content

Commit 2750651

Browse files
committed
add ethers, decrypt keystore into wallet in test
1 parent 0a796a6 commit 2750651

File tree

4 files changed

+94
-4
lines changed

4 files changed

+94
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"packageManager": "[email protected]",
2525
"dependencies": {
2626
"@types/node": "^22.15.32",
27+
"ethers": "^6.15.0",
2728
"tslog": "^4.9.3",
2829
"viem": "^2.31.3"
2930
},

pnpm-lock.yaml

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/client.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Logger
99
} from "tslog"
1010
import xdg from "xdg-portable"
11+
import { Wallet, utils } from "ethers"
1112
import {
1213
createClient,
1314
type GolemBaseClient,
@@ -28,7 +29,13 @@ const log = new Logger<ILogObj>({
2829
minLevel: 3,
2930
})
3031

31-
const keyBytes = fs.readFileSync(xdg.config() + '/golembase/private.key');
32+
// Path to a golembase wallet
33+
const walletPath = path.join(xdg.config(), 'golembase', 'wallet.json');
34+
// The password that the test wallet was encrypted with
35+
const walletTestPassword = "password";
36+
37+
const keystore = fs.readFileSync(walletPath);
38+
const wallet = Wallet.fromEncryptedJsonSync(keystore, walletTestPassword);
3239

3340
let entitiesOwnedCount = 0
3441
let entityKey: Hex = "0x"
@@ -37,7 +44,7 @@ let client: GolemBaseClient
3744

3845
describe("the golem-base client", () => {
3946
it("can be created", async () => {
40-
const key: AccountData = new Tagged("privatekey", keyBytes)
47+
const key: AccountData = new Tagged("privatekey", utils.arrayify(wallet.privateKey))
4148
client = {
4249
local: await createClient(
4350
1337,

test/internal/client.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Logger
99
} from "tslog"
1010
import xdg from "xdg-portable"
11+
import { Wallet, utils } from "ethers"
1112
import {
1213
internal,
1314
type GolemBaseCreate,
@@ -61,7 +62,14 @@ async function ownerAddress(client: internal.GolemBaseClient): Promise<Hex> {
6162
return (await client.walletClient.getAddresses())[0]
6263
}
6364

64-
const keyBytes = fs.readFileSync(xdg.config() + '/golembase/private.key');
65+
// Path to a golembase wallet
66+
const walletPath = path.join(xdg.config(), 'golembase', 'wallet.json');
67+
// The password that the test wallet was encrypted with
68+
const walletTestPassword = "password";
69+
70+
const keystore = fs.readFileSync(walletPath);
71+
const wallet = Wallet.fromEncryptedJsonSync(keystore, walletTestPassword);
72+
6573
let client: GolemBaseClient
6674

6775
const data = generateRandomBytes(32)
@@ -73,7 +81,7 @@ let expirationBlock: number
7381

7482
describe("the internal golem-base client", () => {
7583
it("can be created", async () => {
76-
const key: AccountData = new Tagged("privatekey", keyBytes)
84+
const key: AccountData = new Tagged("privatekey", utils.arrayify(wallet.privateKey))
7785
client = {
7886
local: await internal.createClient(
7987
1337,

0 commit comments

Comments
 (0)