Skip to content

Commit 29d7d5f

Browse files
committed
fix: fixing pending tests
1 parent 28ba530 commit 29d7d5f

2 files changed

Lines changed: 63 additions & 76 deletions

File tree

test/tests/chain-interact.ts

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -120,56 +120,58 @@ suite('Chain Interaction', () => {
120120
// Wait for chain to be ready
121121
await waitForChainReady('http://127.0.0.1:8888', 30000)
122122

123-
// Check if cdt-cpp is installed
123+
// Check if cdt-cpp is installed - skip contract tests if not
124124
try {
125-
execSync('which cdt-cpp')
126-
127-
// Deploy a test contract
128-
contractAccount = 'testcontract'
129-
execSync(`node ${cliPath} wallet account create --name ${contractAccount}`, {
130-
encoding: 'utf8',
131-
})
132-
133-
const contractCode = `
134-
#include <eosio/eosio.hpp>
135-
class [[eosio::contract]] testcontract : public eosio::contract {
136-
public:
137-
using eosio::contract::contract;
138-
139-
struct [[eosio::table]] item {
140-
uint64_t id;
141-
std::string name;
142-
uint64_t primary_key() const { return id; }
143-
};
144-
typedef eosio::multi_index<"items"_n, item> items_table;
145-
146-
[[eosio::action]]
147-
void add(uint64_t id, std::string name) {
148-
items_table items(get_self(), get_self().value);
149-
items.emplace(get_self(), [&](auto& row) {
150-
row.id = id;
151-
row.name = name;
152-
});
153-
}
154-
};
155-
`
156-
const cppPath = path.join(testDir, 'testcontract.cpp')
157-
const wasmPath = path.join(testDir, 'testcontract.wasm')
158-
fs.writeFileSync(cppPath, contractCode)
159-
160-
execSync(`node ${cliPath} compile`, {encoding: 'utf8', cwd: testDir})
161-
execSync(
162-
`node ${cliPath} contract deploy ${wasmPath} --account ${contractAccount} --yes`,
163-
{
164-
encoding: 'utf8',
165-
cwd: testDir,
166-
}
167-
)
168-
} catch (e) {
125+
execSync('which cdt-cpp', {stdio: 'ignore'})
126+
} catch {
169127
// eslint-disable-next-line no-console
170-
console.log('Skipping contract deployment (cdt-cpp not found or failed)')
128+
console.log('Skipping contract deployment tests: cdt-cpp not installed')
171129
contractAccount = ''
130+
return
172131
}
132+
133+
// Deploy a test contract
134+
contractAccount = 'testcontract'
135+
execSync(
136+
`node ${cliPath} wallet account create --name ${contractAccount} --url http://127.0.0.1:8888`,
137+
{encoding: 'utf8'}
138+
)
139+
140+
const contractCode = `
141+
#include <eosio/eosio.hpp>
142+
class [[eosio::contract]] testcontract : public eosio::contract {
143+
public:
144+
using eosio::contract::contract;
145+
146+
struct [[eosio::table]] item {
147+
uint64_t id;
148+
std::string name;
149+
uint64_t primary_key() const { return id; }
150+
};
151+
typedef eosio::multi_index<"items"_n, item> items_table;
152+
153+
[[eosio::action]]
154+
void add(uint64_t id, std::string name) {
155+
items_table items(get_self(), get_self().value);
156+
items.emplace(get_self(), [&](auto& row) {
157+
row.id = id;
158+
row.name = name;
159+
});
160+
}
161+
};
162+
`
163+
const cppPath = path.join(testDir, 'testcontract.cpp')
164+
const wasmPath = path.join(testDir, 'testcontract.wasm')
165+
fs.writeFileSync(cppPath, contractCode)
166+
167+
execSync(`node ${cliPath} compile`, {encoding: 'utf8', cwd: testDir})
168+
execSync(
169+
`node ${cliPath} contract deploy ${wasmPath} --account ${contractAccount} --yes`,
170+
{
171+
encoding: 'utf8',
172+
cwd: testDir,
173+
}
174+
)
173175
})
174176

175177
suiteTeardown(function () {

test/tests/e2e/wallet.ts

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {assert} from 'chai'
22
import {execSync} from 'child_process'
33
import * as fs from 'fs'
44
import * as path from 'path'
5-
import {APIClient, FetchProvider} from '@wharfkit/antelope'
5+
import {APIClient, FetchProvider, KeyType, PrivateKey} from '@wharfkit/antelope'
66
import fetch from 'node-fetch'
77
import {
88
E2ETestContext,
@@ -67,23 +67,13 @@ suite('E2E: Wallet', () => {
6767

6868
test('can add an existing private key to wallet', function () {
6969
if (!ctx) this.skip()
70-
// Generate a private key using the CLI first to get a valid key format
71-
const createOutput = execSync(`node ${ctx.cliPath} wallet create --name tempkey`, {
72-
encoding: 'utf8',
73-
})
74-
75-
// Extract the private key from the output
76-
const privateKeyMatch = createOutput.match(/Private Key: (PVT_K1_[A-Za-z0-9]+)/)
77-
const publicKeyMatch = createOutput.match(/Public Key: (PUB_K1_[A-Za-z0-9]+)/)
78-
assert.isNotNull(privateKeyMatch, 'Should have private key in output')
79-
assert.isNotNull(publicKeyMatch, 'Should have public key in output')
80-
81-
const privateKey = privateKeyMatch![1]
82-
const expectedPublicKey = publicKeyMatch![1]
70+
// Generate a fresh private key (not in wallet yet)
71+
const privateKey = PrivateKey.generate(KeyType.K1)
72+
const expectedPublicKey = privateKey.toPublic().toString()
8373

84-
// Add the same private key with a different name
74+
// Add the private key to the wallet
8575
const addOutput = execSync(
86-
`node ${ctx.cliPath} wallet keys add ${privateKey} --name imported-key`,
76+
`node ${ctx.cliPath} wallet keys add ${privateKey.toString()} --name imported-key`,
8777
{encoding: 'utf8'}
8878
)
8979

@@ -101,27 +91,22 @@ suite('E2E: Wallet', () => {
10191
})
10292
assert.fail('Should have thrown an error')
10393
} catch (error: any) {
104-
assert.include(error.message, 'Invalid private key format')
94+
// The error message is in stdout (CLI outputs to stdout before exiting)
95+
const output = error.stdout || error.message
96+
assert.include(output, 'Invalid private key')
10597
}
10698
})
10799

108100
test('wallet keys add generates name when not specified', function () {
109101
if (!ctx) this.skip()
110-
// Generate a private key using the CLI first
111-
const createOutput = execSync(`node ${ctx.cliPath} wallet create --name tempkey2`, {
112-
encoding: 'utf8',
113-
})
114-
115-
// Extract the private key from the output
116-
const privateKeyMatch = createOutput.match(/Private Key: (PVT_K1_[A-Za-z0-9]+)/)
117-
assert.isNotNull(privateKeyMatch, 'Should have private key in output')
118-
119-
const privateKey = privateKeyMatch![1]
102+
// Generate a fresh private key (not in wallet yet)
103+
const privateKey = PrivateKey.generate(KeyType.K1)
120104

121105
// Add without specifying name
122-
const addOutput = execSync(`node ${ctx.cliPath} wallet keys add ${privateKey}`, {
123-
encoding: 'utf8',
124-
})
106+
const addOutput = execSync(
107+
`node ${ctx.cliPath} wallet keys add ${privateKey.toString()}`,
108+
{encoding: 'utf8'}
109+
)
125110

126111
assert.include(addOutput, '✅ Key added successfully!')
127112
// Should have auto-generated name

0 commit comments

Comments
 (0)