-
Notifications
You must be signed in to change notification settings - Fork 0
Add GoE test scripts covering core commands and Git operations #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b09c915
add test
iteyelmp 5f2d1bc
nff-1
iteyelmp 26e238d
add other test
iteyelmp 475c938
remove test file
iteyelmp 29ef1bb
fix error
iteyelmp a252893
support repo name
iteyelmp f9f5904
fix comment
iteyelmp 5cea987
Merge remote-tracking branch 'origin/main' into test
iteyelmp d802d4b
revert code
iteyelmp a788c0d
remove pk
iteyelmp b1f2c53
fix comment
iteyelmp 58ad78a
fix comment
iteyelmp 1c105af
fix ci
iteyelmp 6ff321f
fix ci
iteyelmp 64600f9
fix Windows error
iteyelmp 7780ed4
fix text
iteyelmp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| name: goe-wallet-ci | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - 'test' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| wallet-create: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: 'yarn' | ||
|
|
||
| - run: yarn install | ||
|
|
||
| - run: yarn build | ||
|
|
||
| - name: Run Wallet Create CI Test | ||
| run: node test/createWalletCI.mjs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import path from 'path'; | ||
| import { runCommand } from "./runCommand.mjs"; | ||
|
|
||
| const DIST_CLI = path.resolve('./dist/cli/index.js'); | ||
| const PASSWORD = '12345678'; | ||
|
|
||
| (async () => { | ||
| try { | ||
| const output = await runCommand( | ||
| 'node', | ||
| [DIST_CLI, 'wallet', 'create'], | ||
| { | ||
| env: { | ||
| GOE_TEST_MODE: '1', | ||
| GOE_TEST_PASSWORD: PASSWORD, | ||
| }, | ||
| capture: true | ||
| } | ||
| ); | ||
| if (!output.includes('Wallet Address:')) { | ||
| throw new Error('Wallet creation failed: no address found'); | ||
| } | ||
|
|
||
| console.log('Unlocking wallet using GOE_TEST_PASSWORD...'); | ||
| await runCommand( | ||
| 'node', | ||
| [DIST_CLI, 'wallet', 'unlock'], | ||
| { | ||
| env: { | ||
| GOE_TEST_MODE: '1', | ||
| GOE_TEST_PASSWORD: PASSWORD, | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| await runCommand('node', [DIST_CLI, 'wallet', 'lock']); | ||
|
|
||
| console.log('✅ Wallet create + unlock/lock test passed!'); | ||
| } catch (e) { | ||
| console.error('❌ Wallet create test failed:', e.message); | ||
| process.exit(1); | ||
| } | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* -------- exec: capture stdout -------- */ | ||
| import {spawn} from "child_process"; | ||
|
|
||
| const SHELL_CMDS = new Set([ | ||
| 'npm', | ||
| 'pnpm', | ||
| 'yarn', | ||
| 'npx', | ||
| ]); | ||
|
|
||
|
|
||
| export function runCommand(cmd, args = [], options = {}) { | ||
| const { | ||
| capture = false, | ||
| env = {}, | ||
| cwd, | ||
| } = options; | ||
|
|
||
| const useShell = SHELL_CMDS.has(cmd); | ||
| return new Promise((resolve, reject) => { | ||
| const child = spawn(cmd, args, { | ||
| shell: useShell, // ⭐ | ||
| stdio: capture ? 'pipe' : 'inherit', | ||
| env: { ...process.env, ...env }, | ||
| cwd, | ||
| }); | ||
|
|
||
| let stdout = ''; | ||
| let stderr = ''; | ||
|
|
||
| if (capture) { | ||
| child.stdout.on('data', d => (stdout += d)); | ||
| child.stderr.on('data', d => (stderr += d)); | ||
| } | ||
|
|
||
| child.on('error', reject); | ||
|
|
||
| child.on('close', (code) => { | ||
| if (code !== 0) { | ||
| return reject( | ||
| new Error( | ||
| stderr.trim() || `Command failed: ${cmd} ${args.join(' ')}` | ||
| ) | ||
| ); | ||
| } | ||
| resolve(capture ? stdout : true); | ||
| }); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,251 @@ | ||
| // test/goeE2ETest.mjs | ||
| import 'dotenv/config'; | ||
| import path from 'path'; | ||
| import fs from 'fs'; | ||
| import { fileURLToPath } from 'url'; | ||
| import { runCommand } from "./runCommand.mjs"; | ||
|
|
||
| const DIST_CLI = path.resolve('./dist/cli/index.js'); | ||
| const CHAIN_ID = '11155111'; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const PROJECT_ROOT = path.resolve(__dirname, '../test'); | ||
| const TEMP_DIR = path.join(PROJECT_ROOT, '/.tmp'); | ||
|
|
||
| const PASSWORD = process.env.GOE_TEST_PASSWORD; | ||
|
|
||
| if (!PASSWORD) { | ||
| console.error('Please set "GOE_TEST_PASSWORD" in .env'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /* ---------------- utils ---------------- */ | ||
|
|
||
| const randomRepoName = () => | ||
| `goe-e2e-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`; | ||
|
|
||
| const stripAnsi = (s) => | ||
| s.replace(/\x1B\[[0-9;]*m/g, ''); | ||
|
|
||
|
|
||
| /* ------------------- Wallet ------------------- */ | ||
| async function checkWalletExists() { | ||
| const out = await runCommand('node', [DIST_CLI, 'wallet', 'list'], { capture: true }); | ||
| if (out.includes('No wallets found')) { | ||
| throw new Error('No wallet exists. Create and fund one first.'); | ||
| } | ||
| } | ||
|
|
||
| async function unlockWallet() { | ||
| console.log('Unlocking wallet using GOE_TEST_PASSWORD...'); | ||
| await runCommand( | ||
| 'node', | ||
| [DIST_CLI, 'wallet', 'unlock'], | ||
| { | ||
| env: { | ||
| GOE_TEST_MODE: '1', | ||
| GOE_TEST_PASSWORD: PASSWORD, | ||
| }, | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| const lockWallet = () => | ||
| runCommand('node', [DIST_CLI, 'wallet', 'lock']); | ||
|
|
||
| /* ------------------- Repo ------------------- */ | ||
| async function createRepo() { | ||
| const name = randomRepoName(); | ||
| const out = await runCommand( | ||
| 'node', | ||
| [DIST_CLI, 'repo', 'create', name, '--chain-id', CHAIN_ID], | ||
| { capture: true } | ||
| ); | ||
| const match = stripAnsi(out).match(/0x[a-fA-F0-9]{40}/); | ||
| if (!match) { | ||
| throw new Error('Repo address not found'); | ||
| } | ||
|
|
||
| return { name, address: match[0] }; | ||
| } | ||
|
|
||
| const listRepos = () => | ||
| runCommand('node', [DIST_CLI, 'repo', 'list', '--chain-id', CHAIN_ID]); | ||
|
|
||
| const listBranches = (addr) => | ||
| runCommand('node', [DIST_CLI, 'repo', 'branches', addr, '--chain-id', CHAIN_ID],); | ||
|
|
||
| const setDefaultBranch = (addr) => | ||
| runCommand('node', [DIST_CLI, 'repo', 'default-branch', addr, 'main', '--chain-id', CHAIN_ID],); | ||
|
|
||
| /* ------------------- Git flow ------------------- */ | ||
| async function gitFlow(goe) { | ||
| const repoPath = path.join(TEMP_DIR, 'flow'); | ||
| fs.mkdirSync(repoPath, { recursive: true }); | ||
| process.chdir(repoPath); | ||
|
|
||
| // init + remote | ||
| await runCommand('git', ['init']); | ||
| await runCommand('git', ['remote', 'add', 'origin', goe]); | ||
| await runCommand('git', ['checkout', '-b', 'main']); | ||
|
|
||
| // init commit | ||
| fs.writeFileSync('README.md', '# GoE E2E\n'); | ||
| await runCommand('git', ['add', '.']); | ||
| await runCommand('git', ['commit', '-m', 'init']); | ||
| await runCommand('git', ['push', 'origin', 'main']); | ||
|
|
||
| // feature branch | ||
| await runCommand('git', ['checkout', '-b', 'feature']); | ||
| fs.writeFileSync('feature.txt', 'feature\n'); | ||
| await runCommand('git', ['add', '.']); | ||
| await runCommand('git', ['commit', '-m', 'feature']); | ||
| await runCommand('git', ['push', 'origin', 'feature']); | ||
|
|
||
| // force push | ||
| fs.writeFileSync('feature.txt', 'force\n'); | ||
| await runCommand('git', ['add', '.']); | ||
| await runCommand('git', ['commit', '-m', 'force-update']); | ||
| await runCommand('git', ['push', '--force', 'origin', 'feature']); | ||
|
|
||
| // delete branch | ||
| await runCommand('git', ['push', 'origin', '--delete', 'feature']); | ||
| } | ||
|
|
||
| async function gitCloneVerify(goe) { | ||
| const clonePath = path.join(TEMP_DIR, 'clone'); | ||
| fs.mkdirSync(clonePath, { recursive: true }); | ||
| process.chdir(TEMP_DIR); | ||
|
|
||
| await runCommand('git', ['clone', goe, clonePath]); | ||
| process.chdir(clonePath); | ||
|
|
||
| const readme = fs.readFileSync(path.join(clonePath, 'README.md'), 'utf8'); | ||
| if (!readme.includes('GoE E2E')) throw new Error('Clone verification failed'); | ||
|
|
||
| const head = await runCommand('git',['symbolic-ref', 'HEAD'], { capture: true }); | ||
| if (!head.includes('refs/heads/main')) throw new Error('HEAD is not refs/heads/main'); | ||
|
|
||
| const branches = await runCommand('git', ['branch', '-r'], { capture: true }); | ||
| if (branches.includes('feature')) throw new Error('Deleted branch still exists'); | ||
| } | ||
|
|
||
| async function gitRejectNonFastForward(goe) { | ||
| const repoPath = path.join(TEMP_DIR, 'nff'); | ||
| fs.mkdirSync(repoPath, { recursive: true }); | ||
| process.chdir(repoPath); | ||
|
|
||
| await runCommand('git', ['clone', goe, '.']); | ||
|
|
||
| // push new file | ||
| fs.writeFileSync('nff.txt', '1'); | ||
| await runCommand('git', ['add', '.']); | ||
| await runCommand('git', ['commit', '-m', 'nff-1']); | ||
| await runCommand('git', ['push', 'origin', 'main']); | ||
|
|
||
| // reset head | ||
| await runCommand('git', ['reset', '--hard', 'HEAD~1']); | ||
|
|
||
| // non-fast-forward push should fail | ||
| try { | ||
| await runCommand('git', ['push', 'origin', 'main']); | ||
| throw new Error('Expected non-fast-forward push to fail'); | ||
| } catch { | ||
| console.log('[expected] non-fast-forward rejected'); | ||
| } | ||
| } | ||
|
|
||
| async function gitMergePush(goe) { | ||
| const repoPath = path.join(TEMP_DIR, 'merge'); | ||
| fs.mkdirSync(repoPath, { recursive: true }); | ||
| process.chdir(repoPath); | ||
|
|
||
| await runCommand('git', ['clone', goe, '.']); | ||
|
|
||
| // create a branch and commit | ||
| await runCommand('git', ['checkout', '-b', 'merge-a']); | ||
| fs.writeFileSync('a.txt', 'a'); | ||
| await runCommand('git', ['add', 'a.txt']); | ||
| await runCommand('git', ['commit', '-m', 'a']); | ||
|
|
||
| // merge back to main | ||
| await runCommand('git', ['checkout', 'main']); | ||
| await runCommand('git', ['merge', 'merge-a']); | ||
|
|
||
| await runCommand('git', ['push', 'origin', 'main']); | ||
| } | ||
|
|
||
| async function gitFetchUpdate(goe) { | ||
| const repoPath = path.join(TEMP_DIR, 'fetch'); | ||
| fs.mkdirSync(repoPath, { recursive: true }); | ||
| process.chdir(repoPath); | ||
|
|
||
| await runCommand('git', ['clone', goe, '.']); | ||
|
|
||
| fs.writeFileSync('fetch.txt', 'x'); | ||
| await runCommand('git', ['add', 'fetch.txt']); | ||
| await runCommand('git', ['commit', '-m', 'fetch-update']); | ||
| await runCommand('git', ['push', 'origin', 'main']); | ||
|
|
||
| // simulate fetch from another clone | ||
| const clonePath = path.join(TEMP_DIR, 'fetch-clone'); | ||
| fs.mkdirSync(clonePath, { recursive: true }); | ||
| await runCommand('git', ['clone', goe, clonePath]); | ||
| process.chdir(clonePath); | ||
|
|
||
| await runCommand('git', ['fetch', 'origin']); | ||
| const result = await runCommand('git', ['log', 'origin/main', '--oneline', '-1'], { capture: true }); | ||
| if (!result.includes('fetch-update')) throw new Error('Fetch did not update origin/main'); | ||
| } | ||
|
|
||
|
|
||
| function cleanup() { | ||
| process.chdir(PROJECT_ROOT); | ||
| fs.rmSync(TEMP_DIR, { recursive: true, force: true }); | ||
| console.log('Local test data cleaned'); | ||
| } | ||
|
|
||
| /* ------------------- main ------------------- */ | ||
| async function npmPrepareAndLink() { | ||
| console.log('\nPreparing local goe-cli...'); | ||
|
|
||
| // 1. build | ||
| await runCommand('npm', ['run', 'build']); | ||
|
|
||
| // 2. link | ||
| console.log('\nLinking local goe-cli...'); | ||
| await runCommand('npm', ['link']); | ||
| } | ||
|
|
||
| (async () => { | ||
| fs.mkdirSync(TEMP_DIR, { recursive: true }); | ||
|
|
||
| // goe | ||
| await npmPrepareAndLink(); | ||
| await checkWalletExists(); | ||
iteyelmp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await unlockWallet(); | ||
| const {name, address} = await createRepo(); | ||
| await listRepos(); | ||
|
|
||
| // git helper | ||
| const goe = `goe://${name}:${CHAIN_ID}` | ||
| try { | ||
| await gitFlow(goe); | ||
| await gitCloneVerify(goe); | ||
| await gitRejectNonFastForward(goe); | ||
| await gitMergePush(goe); | ||
| await gitFetchUpdate(goe); | ||
| } finally { | ||
| cleanup(); | ||
| } | ||
|
|
||
| await listBranches(address); | ||
| await setDefaultBranch(address); | ||
| await lockWallet(); | ||
| console.log('\n=== GoE E2E test finished successfully ==='); | ||
| })().catch((e) => { | ||
| console.error(e.message); | ||
| process.exit(1); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.