-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from CityOfZion/CU-86drpne9j
CU-86drpne9j - Setup Neo-go on neon-dappkit tests
- Loading branch information
Showing
7 changed files
with
255 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -79,3 +79,4 @@ common/autoinstallers/*/.npmrc | |
# Mocha Report | ||
mocha-results.json | ||
**/reporter/ | ||
packages/neon-dappkit/neogo/ |
10 changes: 10 additions & 0 deletions
10
common/changes/@cityofzion/neon-dappkit/CU-86drpne9j_2024-03-22-18-44.json
This file contains 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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@cityofzion/neon-dappkit", | ||
"comment": "", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@cityofzion/neon-dappkit" | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/neon-dappkit/data/protocol.unit_testnet.single.yml
This file contains 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,54 @@ | ||
ProtocolConfiguration: | ||
Magic: 42 | ||
MaxTraceableBlocks: 200000 | ||
TimePerBlock: 100ms | ||
MemPoolSize: 100 | ||
StandbyCommittee: | ||
- 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 | ||
ValidatorsCount: 1 | ||
VerifyTransactions: true | ||
P2PSigExtensions: true | ||
Hardforks: | ||
Aspidochelone: 25 | ||
|
||
ApplicationConfiguration: | ||
SkipBlockVerification: false | ||
# LogPath could be set up in case you need stdout logs to some proper file. | ||
# LogPath: "./log/neogo.log" | ||
DBConfiguration: | ||
Type: "inmemory" #other options: 'inmemory','boltdb' | ||
# DB type options. Uncomment those you need in case you want to switch DB type. | ||
# LevelDBOptions: | ||
# DataDirectoryPath: "./chains/unit_testnet" | ||
# BoltDBOptions: | ||
# FilePath: "./chains/unit_testnet.bolt" | ||
P2P: | ||
Addresses: | ||
- ":0" # in form of "[host]:[port][:announcedPort]" | ||
DialTimeout: 3s | ||
ProtoTickInterval: 2s | ||
PingInterval: 30s | ||
PingTimeout: 90s | ||
MinPeers: 0 | ||
MaxPeers: 10 | ||
AttemptConnPeers: 5 | ||
Relay: true | ||
Consensus: | ||
Enabled: true | ||
UnlockWallet: | ||
Path: "wallet1_solo.json" | ||
Password: "one" | ||
RPC: | ||
MaxGasInvoke: 15 | ||
Enabled: true | ||
Addresses: | ||
- "127.0.0.1:0" # let the system choose port dynamically | ||
EnableCORSWorkaround: false | ||
Prometheus: | ||
Enabled: false #since it's not useful for unit tests. | ||
Addresses: | ||
- ":2112" | ||
Pprof: | ||
Enabled: false #since it's not useful for unit tests. | ||
Addresses: | ||
- ":2113" |
This file contains 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,55 @@ | ||
{ | ||
"version": "1.0", | ||
"accounts": [ | ||
{ | ||
"address": "Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn", | ||
"key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR", | ||
"label": "", | ||
"contract": { | ||
"script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBVuezJw==", | ||
"parameters": [ | ||
{ | ||
"name": "parameter0", | ||
"type": "Signature" | ||
} | ||
], | ||
"deployed": false | ||
}, | ||
"lock": false, | ||
"isDefault": false | ||
}, | ||
{ | ||
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq", | ||
"key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR", | ||
"label": "", | ||
"contract": { | ||
"script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6", | ||
"parameters": [ | ||
{ | ||
"name": "parameter0", | ||
"type": "Signature" | ||
}, | ||
{ | ||
"name": "parameter1", | ||
"type": "Signature" | ||
}, | ||
{ | ||
"name": "parameter2", | ||
"type": "Signature" | ||
} | ||
], | ||
"deployed": false | ||
}, | ||
"lock": false, | ||
"isDefault": false | ||
} | ||
], | ||
"scrypt": { | ||
"n": 2, | ||
"r": 1, | ||
"p": 1 | ||
}, | ||
"extra": { | ||
"Tokens": null | ||
} | ||
} |
This file contains 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 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,40 @@ | ||
import { ChildProcess, spawn } from 'child_process' | ||
import * as path from 'path'; | ||
import assert from 'assert' | ||
|
||
function wait(ms: number) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms) | ||
}) | ||
} | ||
|
||
function neoGoPath() { | ||
return path.resolve(path.join(__dirname, '..', 'neogo', 'neogo')) | ||
} | ||
|
||
function getDataDir() { | ||
return path.resolve(path.join(__dirname, '..', 'data')) | ||
} | ||
|
||
describe('NeonEventListener', function () { | ||
this.timeout(60000) | ||
let childProcess: ChildProcess; | ||
|
||
beforeEach(async function () { | ||
const neoGo = neoGoPath(); | ||
const dataDir = getDataDir(); | ||
|
||
childProcess = spawn(neoGo, ['node', '--config-file', `${dataDir}/protocol.unit_testnet.single.yml`, '--relative-path', dataDir], {}) | ||
await wait(1200) | ||
|
||
return true | ||
}) | ||
|
||
afterEach('Tear down', async function () { | ||
return childProcess.kill(); | ||
}) | ||
|
||
it('does execute neoGo', async () => { | ||
assert(childProcess !== undefined, 'child process running neo-go is set') | ||
}) | ||
}) |
This file contains 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,90 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { https } from 'follow-redirects'; | ||
import { execSync } from "child_process"; | ||
|
||
async function installNeoGo(): Promise<string | undefined> { | ||
const toolsDir = path.resolve(path.join(__dirname, '..', 'neogo')); | ||
|
||
const platform = process.platform; | ||
let osType = platform.toString(); | ||
let fileExtension = ''; | ||
if (platform == "win32") { | ||
osType = "windows"; | ||
fileExtension = '.exe'; | ||
} | ||
|
||
const goCompilerExecutablePath = path.resolve(path.join(toolsDir, `neogo${fileExtension}`)) | ||
if (fs.existsSync(goCompilerExecutablePath)) { | ||
return goCompilerExecutablePath; | ||
} | ||
|
||
const version = '0.105.1'; | ||
const arch = process.arch; | ||
|
||
let archType = 'arm64'; | ||
if (arch == 'x64') { | ||
archType = 'amd64'; | ||
} | ||
|
||
if (osType == "windows" && archType == "arm64") { | ||
throw new Error(`Unsupported architecture: ${osType}-${arch}`); | ||
} | ||
|
||
|
||
if (!fs.existsSync(toolsDir)) { | ||
fs.mkdirSync(toolsDir, { recursive: true }) | ||
} | ||
|
||
if (!fs.existsSync(goCompilerExecutablePath)) { | ||
if (osType == "darwin" && archType == "arm64") { | ||
const neoGoArchivePage = "https://github.com/nspcc-dev/neo-go/archive/refs/tags"; | ||
const downloadUrl = `${neoGoArchivePage}/v${version}.zip`; | ||
const zipPath = path.join(toolsDir, 'neogo.zip'); | ||
|
||
await downloadAndVerify(downloadUrl, zipPath); | ||
|
||
const AdmZip = require('adm-zip'); | ||
const zip = new AdmZip(zipPath); | ||
|
||
zip.extractAllTo(toolsDir, true); | ||
const extractedFolderPath = path.join(toolsDir, "neo-go-" + version); | ||
console.log(extractedFolderPath); | ||
execSync(`make -C ${extractedFolderPath}`); | ||
|
||
} else { | ||
const fileName = `neo-go-${osType}-${archType}${fileExtension}`; | ||
const neoGoReleasePage = "https://github.com/nspcc-dev/neo-go/releases"; | ||
const downloadUrl = `${neoGoReleasePage}/download/v${version}/${fileName}`; | ||
|
||
await downloadAndVerify(downloadUrl, goCompilerExecutablePath); | ||
} | ||
} | ||
|
||
fs.chmodSync(goCompilerExecutablePath, '755') | ||
execSync(`${goCompilerExecutablePath} node -h`); | ||
return goCompilerExecutablePath; | ||
} | ||
|
||
|
||
async function downloadAndVerify(downloadUrl: string, downloadPath: string) { | ||
try { | ||
await new Promise<void>((resolve, reject) => { | ||
const file = fs.createWriteStream(downloadPath); | ||
https.get(downloadUrl, (response: { pipe: (stream: fs.WriteStream) => void; }) => { | ||
response.pipe(file); | ||
file.on('finish', () => { | ||
file.close(); | ||
resolve(); | ||
}); | ||
}).on('error', (err: { message: any; }) => { | ||
fs.unlink(downloadPath, () => { }); // Delete the file async on error | ||
reject(err.message); | ||
}); | ||
}); | ||
} catch (error) { | ||
console.error('Error:', error); | ||
} | ||
} | ||
|
||
installNeoGo(); |