diff --git a/.github/workflows/TEST-bdd.yml b/.github/workflows/TEST-bdd.yml index a57ff6874..c940b0ad1 100644 --- a/.github/workflows/TEST-bdd.yml +++ b/.github/workflows/TEST-bdd.yml @@ -24,7 +24,7 @@ jobs: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 graphdb: - image: khaller/graphdb-free:latest + image: khaller/graphdb-free:1.3.5-graphdb9.11.2 ports: - 7200:7200 strategy: diff --git a/config/config.json b/config/config.json index c308d08d5..a734b3208 100644 --- a/config/config.json +++ b/config/config.json @@ -266,7 +266,9 @@ "blockchainTitle": "ganache", "networkId": "ganache::testnet", "hubContractAddress": "0x209679fA3B658Cd0fC74473aF28243bfe78a9b12", - "rpcEndpoints": ["http://localhost:7545"] + "rpcEndpoints": ["http://localhost:7545"], + "initialStakeAmount": 50000, + "initialAskAmount": 0.2 } } } diff --git a/ot-node.js b/ot-node.js index d3bd0de8a..ba1b9167a 100644 --- a/ot-node.js +++ b/ot-node.js @@ -9,6 +9,7 @@ import { CONTRACTS, MIN_NODE_VERSION } from './src/constants/constants.js'; import FileService from './src/service/file-service.js'; import OtnodeUpdateCommand from './src/commands/common/otnode-update-command.js'; import OtAutoUpdater from './src/modules/auto-updater/implementation/ot-auto-updater.js'; +import PullBlockchainShardingTableMigration from './src/migration/pull-sharding-table-migration.js'; const require = createRequire(import.meta.url); const pjson = require('./package.json'); @@ -43,6 +44,7 @@ class OTNode { this.initializeEventEmitter(); await this.initializeModules(); + await this.executePullShardingTableMigration(); await this.listenOnHubContractChanges(); await this.createProfiles(); @@ -220,6 +222,26 @@ class OTNode { } } + async executePullShardingTableMigration() { + if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') return; + + const blockchainModuleManager = this.container.resolve('blockchainModuleManager'); + const repositoryModuleManager = this.container.resolve('repositoryModuleManager'); + const validationModuleManager = this.container.resolve('validationModuleManager'); + + const migration = new PullBlockchainShardingTableMigration( + 'pullShardingTableMigration', + this.logger, + this.config, + repositoryModuleManager, + blockchainModuleManager, + validationModuleManager, + ); + if (!(await migration.migrationAlreadyExecuted())) { + await migration.migrate(); + } + } + async initializeShardingTableService() { const blockchainModuleManager = this.container.resolve('blockchainModuleManager'); const initShardingServices = blockchainModuleManager @@ -290,6 +312,12 @@ class OTNode { getLastCheckedBlock, updateLastCheckedBlock, ); + await blockchainModuleManager.getAllPastEvents( + CONTRACTS.STAKING_CONTRACT, + onEventsReceived, + getLastCheckedBlock, + updateLastCheckedBlock, + ); await blockchainModuleManager.getAllPastEvents( CONTRACTS.PROFILE_CONTRACT, onEventsReceived, @@ -357,6 +385,9 @@ class OTNode { const blockchainModuleManager = this.container.resolve('blockchainModuleManager'); const that = this; blockchainModuleManager.getImplementationNames().map(async (blockchain) => { + eventEmitter.on(`${blockchain}-NewContract`, async () => { + await that.reinitializeContracts(blockchainModuleManager, blockchain); + }); eventEmitter.on(`${blockchain}-ContractChanged`, async (event) => { await that.reinitializeContracts(blockchainModuleManager, blockchain); if (event.contractName === 'ShardingTable') { diff --git a/package-lock.json b/package-lock.json index 360154398..e7f3bce8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.0.1", + "version": "6.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.0.1", + "version": "6.0.2", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", @@ -83,7 +83,7 @@ "@polkadot/util-crypto": "^10.1.7", "@truffle/hdwallet-provider": "^2.0.16", "chai": "^4.3.6", - "dkg.js": "^6.0.0-beta.3.1.2", + "dkg.js": "^6.0.0-beta.3.5.1", "eslint": "^8.23.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.5.0", @@ -7841,53 +7841,18 @@ } }, "node_modules/dkg.js": { - "version": "6.0.0-beta.3.3.0", - "resolved": "https://registry.npmjs.org/dkg.js/-/dkg.js-6.0.0-beta.3.3.0.tgz", - "integrity": "sha512-hlSkSlRWa52pxjBnhyYsVdU0KyoL+Lrv/sCyAWh+38mCtSR4liAhavqsyngzFZd/boz8llF6ofAHRz1B9wHnPw==", + "version": "6.0.0-beta.3.5.1", + "resolved": "https://registry.npmjs.org/dkg.js/-/dkg.js-6.0.0-beta.3.5.1.tgz", + "integrity": "sha512-AWkl9r6qBq8C+qWiw8tmQyO38yylJwBiVb3JjJ+m1Dj5gbaHIO8C/ljz+qsxyVD+xx8a2rCIzpxTZqTdo4t8mA==", "dev": true, "dependencies": { - "assertion-tools": "^1.0.9", + "assertion-tools": "^2.0.2", "axios": "^0.27.2", - "dkg-evm-module": "^1.1.3", + "dkg-evm-module": "^3.2.1", "jsonld": "^8.1.0", "web3": "^1.7.3" } }, - "node_modules/dkg.js/node_modules/assertion-tools": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/assertion-tools/-/assertion-tools-1.2.1.tgz", - "integrity": "sha512-6Sb09HN0CF8aROAytkJbI1pZZ0WV3Et2ddxtLd4OmpwXup5GuqHaL6w1UzHb1hknx2slyXiQ/R6tD55tao3Jog==", - "dev": true, - "dependencies": { - "jsonld": "^8.1.0", - "keccak256": "^1.0.6", - "merkletreejs": "^0.3.2", - "multiformats": "^9.9.0", - "web3": "^1.8.1" - } - }, - "node_modules/dkg.js/node_modules/dkg-evm-module": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/dkg-evm-module/-/dkg-evm-module-1.1.3.tgz", - "integrity": "sha512-5VKaNNG+hAdMpSOjVEdsnnnhhTjIPOC0TMpUzI+X0YdW3Wa6OTce9qX0lkJS3QwBmBgKf6Vk0T8qtVy89FMFfg==", - "dev": true - }, - "node_modules/dkg.js/node_modules/merkletreejs": { - "version": "0.3.9", - "resolved": "https://registry.npmjs.org/merkletreejs/-/merkletreejs-0.3.9.tgz", - "integrity": "sha512-NjlATjJr4NEn9s8v/VEHhgwRWaE1eA/Une07d9SEqKzULJi1Wsh0Y3svwJdP2bYLMmgSBHzOrNydMWM1NN9VeQ==", - "dev": true, - "dependencies": { - "bignumber.js": "^9.0.1", - "buffer-reverse": "^1.0.1", - "crypto-js": "^3.1.9-1", - "treeify": "^1.1.0", - "web3-utils": "^1.3.4" - }, - "engines": { - "node": ">= 7.6.0" - } - }, "node_modules/dns-over-http-resolver": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/dns-over-http-resolver/-/dns-over-http-resolver-1.2.3.tgz", @@ -27228,50 +27193,16 @@ } }, "dkg.js": { - "version": "6.0.0-beta.3.3.0", - "resolved": "https://registry.npmjs.org/dkg.js/-/dkg.js-6.0.0-beta.3.3.0.tgz", - "integrity": "sha512-hlSkSlRWa52pxjBnhyYsVdU0KyoL+Lrv/sCyAWh+38mCtSR4liAhavqsyngzFZd/boz8llF6ofAHRz1B9wHnPw==", + "version": "6.0.0-beta.3.5.1", + "resolved": "https://registry.npmjs.org/dkg.js/-/dkg.js-6.0.0-beta.3.5.1.tgz", + "integrity": "sha512-AWkl9r6qBq8C+qWiw8tmQyO38yylJwBiVb3JjJ+m1Dj5gbaHIO8C/ljz+qsxyVD+xx8a2rCIzpxTZqTdo4t8mA==", "dev": true, "requires": { - "assertion-tools": "^1.0.9", + "assertion-tools": "^2.0.2", "axios": "^0.27.2", - "dkg-evm-module": "^1.1.3", + "dkg-evm-module": "^3.2.1", "jsonld": "^8.1.0", "web3": "^1.7.3" - }, - "dependencies": { - "assertion-tools": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/assertion-tools/-/assertion-tools-1.2.1.tgz", - "integrity": "sha512-6Sb09HN0CF8aROAytkJbI1pZZ0WV3Et2ddxtLd4OmpwXup5GuqHaL6w1UzHb1hknx2slyXiQ/R6tD55tao3Jog==", - "dev": true, - "requires": { - "jsonld": "^8.1.0", - "keccak256": "^1.0.6", - "merkletreejs": "^0.3.2", - "multiformats": "^9.9.0", - "web3": "^1.8.1" - } - }, - "dkg-evm-module": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/dkg-evm-module/-/dkg-evm-module-1.1.3.tgz", - "integrity": "sha512-5VKaNNG+hAdMpSOjVEdsnnnhhTjIPOC0TMpUzI+X0YdW3Wa6OTce9qX0lkJS3QwBmBgKf6Vk0T8qtVy89FMFfg==", - "dev": true - }, - "merkletreejs": { - "version": "0.3.9", - "resolved": "https://registry.npmjs.org/merkletreejs/-/merkletreejs-0.3.9.tgz", - "integrity": "sha512-NjlATjJr4NEn9s8v/VEHhgwRWaE1eA/Une07d9SEqKzULJi1Wsh0Y3svwJdP2bYLMmgSBHzOrNydMWM1NN9VeQ==", - "dev": true, - "requires": { - "bignumber.js": "^9.0.1", - "buffer-reverse": "^1.0.1", - "crypto-js": "^3.1.9-1", - "treeify": "^1.1.0", - "web3-utils": "^1.3.4" - } - } } }, "dns-over-http-resolver": { diff --git a/package.json b/package.json index d84ee20e8..24b59e712 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.1", + "version": "6.0.2", "description": "OTNode V6", "main": "index.js", "type": "module", @@ -50,7 +50,7 @@ "@polkadot/util-crypto": "^10.1.7", "@truffle/hdwallet-provider": "^2.0.16", "chai": "^4.3.6", - "dkg.js": "^6.0.0-beta.3.1.2", + "dkg.js": "^6.0.0-beta.3.5.1", "eslint": "^8.23.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.5.0", diff --git a/scripts/set-ask.js b/scripts/set-ask.js index eae1209a6..a2681765c 100644 --- a/scripts/set-ask.js +++ b/scripts/set-ask.js @@ -11,6 +11,8 @@ const argv = require('minimist')(process.argv.slice(1), { string: ['ask', 'privateKey', 'hubContractAddress'], }); +const devEnvironment = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'; + async function setAsk(rpcEndpoint, ask, walletPrivateKey, hubContractAddress) { const provider = new ethers.providers.JsonRpcProvider(rpcEndpoint); const wallet = new ethers.Wallet(walletPrivateKey); @@ -33,7 +35,7 @@ async function setAsk(rpcEndpoint, ask, walletPrivateKey, hubContractAddress) { const walletSigner = wallet.connect(provider); await profile.connect(walletSigner).setAsk(identityId, askWei, { - gasPrice: process.env.NODE_ENV === 'development' ? undefined : 8, + gasPrice: devEnvironment ? undefined : 8, gasLimit: 500_000, }); } diff --git a/scripts/set-stake.js b/scripts/set-stake.js index 11a6a931a..fd594fe95 100644 --- a/scripts/set-stake.js +++ b/scripts/set-stake.js @@ -17,6 +17,8 @@ const argv = require('minimist')(process.argv.slice(1), { ], }); +const devEnvironment = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'; + async function setStake( rpcEndpoint, stake, @@ -51,14 +53,14 @@ async function setStake( await tokenContract .connect(managementWalletSigner) .increaseAllowance(stakingContractAddress, stakeWei, { - gasPrice: process.env.NODE_ENV === 'development' ? undefined : 8, + gasPrice: devEnvironment ? undefined : 8, gasLimit: 500_000, }); // TODO: Add ABI instead of hard-coded function definition await stakingContract .connect(managementWalletSigner) ['addStake(uint72,uint96)'](identityId, stakeWei, { - gasPrice: process.env.NODE_ENV === 'development' ? undefined : 1_000, + gasPrice: devEnvironment ? undefined : 1_000, gasLimit: 500_000, }); } diff --git a/src/constants/constants.js b/src/constants/constants.js index 5093ee1e5..ec0075f78 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -331,6 +331,7 @@ export const QUERY_TYPES = { */ export const CONTRACTS = { SHARDING_TABLE_CONTRACT: 'ShardingTableContract', + STAKING_CONTRACT: 'StakingContract', PROFILE_CONTRACT: 'ProfileContract', HUB_CONTRACT: 'hubContract', }; diff --git a/src/migration/pull-sharding-table-migration.js b/src/migration/pull-sharding-table-migration.js new file mode 100644 index 000000000..b57e802e0 --- /dev/null +++ b/src/migration/pull-sharding-table-migration.js @@ -0,0 +1,88 @@ +import { ethers } from 'ethers'; +import BaseMigration from './base-migration.js'; + +class PullBlockchainShardingTableMigration extends BaseMigration { + constructor( + migrationName, + logger, + config, + repositoryModuleManager, + blockchainModuleManager, + validationModuleManager, + ) { + super(migrationName, logger, config); + this.repositoryModuleManager = repositoryModuleManager; + this.blockchainModuleManager = blockchainModuleManager; + this.validationModuleManager = validationModuleManager; + } + + async executeMigration() { + const promises = this.blockchainModuleManager + .getImplementationNames() + .map(async (blockchainId) => { + this.logger.debug( + `Removing nodes from local sharding table for blockchain ${blockchainId}.`, + ); + await this.repositoryModuleManager.removeShardingTablePeerRecords(blockchainId); + + const shardingTableLength = Number( + await this.blockchainModuleManager.getShardingTableLength(blockchainId), + ); + let startingIdentityId = await this.blockchainModuleManager.getShardingTableHead( + blockchainId, + ); + const pageSize = 10; + const shardingTable = []; + + this.logger.debug( + `Started pulling ${shardingTableLength} nodes from blockchain sharding table.`, + ); + + let sliceIndex = 0; + + while (shardingTable.length < shardingTableLength) { + // eslint-disable-next-line no-await-in-loop + const nodes = await this.blockchainModuleManager.getShardingTablePage( + blockchainId, + startingIdentityId, + pageSize, + ); + shardingTable.push( + ...nodes.slice(sliceIndex).filter((node) => node.nodeId !== '0x'), + ); + sliceIndex = 1; + startingIdentityId = nodes[nodes.length - 1].identityId; + } + + this.logger.debug( + `Finished pulling ${shardingTable.length} nodes from blockchain sharding table.`, + ); + + await this.repositoryModuleManager.createManyPeerRecords( + await Promise.all( + shardingTable.map(async (peer) => { + const nodeId = this.blockchainModuleManager.convertHexToAscii( + blockchainId, + peer.nodeId, + ); + + return { + peer_id: nodeId, + blockchain_id: blockchainId, + ask: ethers.utils.formatUnits(peer.ask, 'ether'), + stake: ethers.utils.formatUnits(peer.stake, 'ether'), + sha256: await this.validationModuleManager.callHashFunction( + 1, + nodeId, + ), + }; + }), + ), + ); + }); + + await Promise.all(promises); + } +} + +export default PullBlockchainShardingTableMigration; diff --git a/src/modules/blockchain/blockchain-module-manager.js b/src/modules/blockchain/blockchain-module-manager.js index 945d05573..bd19de77e 100644 --- a/src/modules/blockchain/blockchain-module-manager.js +++ b/src/modules/blockchain/blockchain-module-manager.js @@ -35,6 +35,10 @@ class BlockchainModuleManager extends BaseModuleManager { ]); } + async getNodeStake(blockchain, identityId) { + return this.callImplementationFunction(blockchain, 'getNodeStake', [identityId]); + } + async getIdentityId(blockchain) { return this.callImplementationFunction(blockchain, 'getIdentityId'); } diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index c6dfacd91..f207b253e 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -17,6 +17,7 @@ const require = createRequire(import.meta.url); const AbstractAsset = require('dkg-evm-module/build/contracts/AbstractAsset.json'); const AssertionStorage = require('dkg-evm-module/build/contracts/AssertionStorage.json'); const Staking = require('dkg-evm-module/build/contracts/Staking.json'); +const StakingStorage = require('dkg-evm-module/build/contracts/StakingStorage.json'); const ERC20Token = require('dkg-evm-module/build/contracts/ERC20Token.json'); const HashingProxy = require('dkg-evm-module/build/contracts/HashingProxy.json'); const Hub = require('dkg-evm-module/build/contracts/Hub.json'); @@ -132,6 +133,16 @@ class Web3Service { ); this.StakingContract = new this.web3.eth.Contract(Staking.abi, stakingContractAddress); + const stakingStorageAddress = await this.callContractFunction( + this.hubContract, + 'getContractAddress', + ['StakingStorage'], + ); + this.StakingStorageContract = new this.web3.eth.Contract( + StakingStorage.abi, + stakingStorageAddress, + ); + const hashingProxyAddress = await this.callContractFunction( this.hubContract, 'getContractAddress', @@ -528,6 +539,10 @@ class Web3Service { return this.callContractFunction(this.hubContract, 'isAssetStorage', [contractAddress]); } + async getNodeStake(identityId) { + return this.callContractFunction(this.StakingStorageContract, 'totalStakes', [identityId]); + } + async getAssertionIdByIndex(assetContractAddress, tokenId, index) { return this.callContractFunction( this.assetStorageContracts[assetContractAddress.toLowerCase()], diff --git a/src/modules/network/implementation/libp2p-service.js b/src/modules/network/implementation/libp2p-service.js index aa536fd19..89982a25c 100644 --- a/src/modules/network/implementation/libp2p-service.js +++ b/src/modules/network/implementation/libp2p-service.js @@ -25,6 +25,8 @@ import { LIBP2P_KEY_FILENAME, } from '../../../constants/constants.js'; +const devEnvironment = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'; + const initializationObject = { addresses: { listen: ['/ip4/0.0.0.0/tcp/9000'], @@ -67,7 +69,10 @@ class Libp2pService { }; let id; if (!this.config.peerId) { - this.config.privateKey = await this.readPrivateKeyFromFile(); + if (!devEnvironment || !this.config.privateKey) { + this.config.privateKey = await this.readPrivateKeyFromFile(); + } + if (!this.config.privateKey) { id = await _create({ bits: 1024, keyType: 'RSA' }); this.config.privateKey = id.toJSON().privKey; diff --git a/src/modules/repository/implementation/sequelize/sequelize-repository.js b/src/modules/repository/implementation/sequelize/sequelize-repository.js index 66e9ad4d5..16f51338e 100644 --- a/src/modules/repository/implementation/sequelize/sequelize-repository.js +++ b/src/modules/repository/implementation/sequelize/sequelize-repository.js @@ -258,6 +258,12 @@ class SequelizeRepository { }); } + async removeShardingTablePeerRecords(blockchain) { + return this.models.shard.destroy({ + where: { blockchain_id: blockchain }, + }); + } + async createPeerRecord(peerId, blockchain, ask, stake, lastSeen, sha256) { return this.models.shard.create( { diff --git a/src/modules/repository/repository-module-manager.js b/src/modules/repository/repository-module-manager.js index 8da194c33..f304a1bb5 100644 --- a/src/modules/repository/repository-module-manager.js +++ b/src/modules/repository/repository-module-manager.js @@ -158,6 +158,12 @@ class RepositoryModuleManager extends BaseModuleManager { } } + async removeShardingTablePeerRecords(blockchain) { + if (this.initialized) { + return this.getImplementation().module.removeShardingTablePeerRecords(blockchain); + } + } + async createPeerRecord(peerId, blockchain, ask, stake, lastSeen, sha256) { if (this.initialized) { return this.getImplementation().module.createPeerRecord( diff --git a/src/service/sharding-table-service.js b/src/service/sharding-table-service.js index 61f1055f5..6cd159d58 100644 --- a/src/service/sharding-table-service.js +++ b/src/service/sharding-table-service.js @@ -52,6 +52,11 @@ class ShardingTableService { return; } + this.logger.debug( + `Removing nodes from local sharding table for blockchain ${blockchainId}.`, + ); + await this.repositoryModuleManager.removeShardingTablePeerRecords(blockchainId); + const shardingTableLength = Number( await this.blockchainModuleManager.getShardingTableLength(blockchainId), ); @@ -147,7 +152,7 @@ class ShardingTableService { this.repositoryModuleManager.markBlockchainEventAsProcessed(event.id); }); - this.eventEmitter.on(`${blockchainId}-StakeIncreased`, (event) => { + this.eventEmitter.on(`${blockchainId}-StakeIncreased`, async (event) => { const eventData = JSON.parse(event.data); const nodeId = this.blockchainModuleManager.convertHexToAscii( event.blockchain_id, @@ -159,12 +164,18 @@ class ShardingTableService { this.repositoryModuleManager.updatePeerStake( blockchainId, nodeId, - ethers.utils.formatUnits(eventData.ask, 'ether'), + ethers.utils.formatUnits( + await this.blockchainModuleManager.getNodeStake( + blockchainId, + eventData.identityId, + ), + 'ether', + ), ); this.repositoryModuleManager.markBlockchainEventAsProcessed(event.id); }); - this.eventEmitter.on(`${blockchainId}-StakeWithdrawalStarted`, (event) => { + this.eventEmitter.on(`${blockchainId}-StakeWithdrawalStarted`, async (event) => { const eventData = JSON.parse(event.data); const nodeId = this.blockchainModuleManager.convertHexToAscii( event.blockchain_id, @@ -176,7 +187,13 @@ class ShardingTableService { this.repositoryModuleManager.updatePeerStake( blockchainId, nodeId, - ethers.utils.formatUnits(eventData.ask, 'ether'), + ethers.utils.formatUnits( + await this.blockchainModuleManager.getNodeStake( + blockchainId, + eventData.identityId, + ), + 'ether', + ), ); this.repositoryModuleManager.markBlockchainEventAsProcessed(event.id); }); diff --git a/test/bdd/features/get-errors.feature b/test/bdd/features/get-errors.feature index 0af1a5eb4..2712b5e74 100644 --- a/test/bdd/features/get-errors.feature +++ b/test/bdd/features/get-errors.feature @@ -9,7 +9,7 @@ Feature: Get errors test And I wait for 10 seconds And I call get directly to ot-node 1 with nonExistentUAL And I wait for last resolve to finalize - Then Last GET operation finished with status: GetAssertionIdError + Then Last GET operation finished with status: GetLocalError #@get-errors #Scenario: GET operation result on a node with minimum replication factor greater than the number of nodes diff --git a/test/bdd/steps/api/resolve.mjs b/test/bdd/steps/api/resolve.mjs index 66a4aac19..f8f82a857 100644 --- a/test/bdd/steps/api/resolve.mjs +++ b/test/bdd/steps/api/resolve.mjs @@ -7,6 +7,7 @@ import {readFile} from "fs/promises"; const requests = JSON.parse(await readFile("test/bdd/steps/api/datasets/requests.json")); const httpApiHelper = new HttpApiHelper() + When( /^I get operation result from node (\d+) for last published assertion/, { timeout: 120000 }, diff --git a/test/bdd/steps/blockchain.mjs b/test/bdd/steps/blockchain.mjs index fa86f9c9e..abdedee13 100644 --- a/test/bdd/steps/blockchain.mjs +++ b/test/bdd/steps/blockchain.mjs @@ -1,11 +1,13 @@ import { Given } from '@cucumber/cucumber'; import { expect } from 'chai'; import LocalBlockchain from './lib/local-blockchain.mjs'; +import fs from 'fs'; Given(/^the blockchain is set up$/, { timeout: 60000 }, function blockchinSetup(done) { expect(this.state.localBlockchain, "localBlockchain shouldn't be defined").to.be.equal(null); + const blockchainConsole = new console.Console(fs.createWriteStream(`${this.state.scenarionLogDir}/blockchain.log`)); - this.state.localBlockchain = new LocalBlockchain({ logger: this.logger }); + this.state.localBlockchain = new LocalBlockchain({ logger: blockchainConsole }); this.state.localBlockchain .initialize() .then(() => { diff --git a/test/bdd/steps/common.mjs b/test/bdd/steps/common.mjs index 83ab3f608..8d0f1c20f 100644 --- a/test/bdd/steps/common.mjs +++ b/test/bdd/steps/common.mjs @@ -25,6 +25,8 @@ Given( const managementWallet = wallets[nodeIndex + 1 + Math.floor(wallets.length / 2)]; const rpcPort = 8901 + nodeIndex; const nodeName = `origintrail-test-${nodeIndex}`; + const sharesTokenName = `origintrail-test-${nodeIndex}`; + const sharesTokenSymbol = `OT-T-${nodeIndex}`; const nodeConfiguration = DeepExtend( {}, defaultConfiguration, @@ -35,6 +37,8 @@ Given( nodeIndex, nodeName, rpcPort, + sharesTokenName, + sharesTokenSymbol ), ); const forkedNode = stepsUtils.forkNode(nodeConfiguration); @@ -133,6 +137,8 @@ Given( this.state.localBlockchain.getWallets()[nodeIndex + 1 + Math.floor(wallets.length / 2)]; const rpcPort = 8901 + nodeIndex; const nodeName = `origintrail-test-${nodeIndex}`; + const sharesTokenName = `origintrail-test-${nodeIndex}`; + const sharesTokenSymbol = `OT-T-${nodeIndex}`; const nodeConfiguration = DeepExtend( {}, defaultConfiguration, @@ -143,6 +149,8 @@ Given( nodeIndex, nodeName, rpcPort, + sharesTokenName, + sharesTokenSymbol ), ); const propertyNameSplitLen = propertyNameSplit.length; diff --git a/test/bdd/steps/config/origintrail-test-bootstrap-config.json b/test/bdd/steps/config/origintrail-test-bootstrap-config.json index 6db957c39..80a2ecf6c 100644 --- a/test/bdd/steps/config/origintrail-test-bootstrap-config.json +++ b/test/bdd/steps/config/origintrail-test-bootstrap-config.json @@ -11,7 +11,10 @@ "hubContractAddress": "0x209679fA3B658Cd0fC74473aF28243bfe78a9b12", "evmOperationalWalletPublicKey": "0xd6879C0A03aDD8cFc43825A42a3F3CF44DB7D2b9", "evmOperationalWalletPrivateKey": "0x02b39cac1532bef9dba3e36ec32d3de1e9a88f1dda597d3ac6e2130aed9adc4e", - "evmManagementWalletPublicKey": "0xBaF76aC0d0ef9a2FFF76884d54C9D3e270290a43" + "evmManagementWalletPublicKey": "0xBaF76aC0d0ef9a2FFF76884d54C9D3e270290a43", + "evmManagementWalletPrivateKey": "0x9b9af041edc816692276ac3c8f1d5565e3c01ddff80ec982943a29bd8d1d8863", + "sharesTokenName": "LocalNode0", + "sharesTokenSymbol": "LN0" } } } diff --git a/test/bdd/steps/lib/local-blockchain.mjs b/test/bdd/steps/lib/local-blockchain.mjs index a6bbba0d4..9c1fea85a 100644 --- a/test/bdd/steps/lib/local-blockchain.mjs +++ b/test/bdd/steps/lib/local-blockchain.mjs @@ -65,7 +65,7 @@ const contentAsset = JSON.parse( await readFile('node_modules/dkg-evm-module/build/contracts/ContentAsset.json') ) const contentAssetStorage = JSON.parse( - await readFile('node_modules/dkg-evm-module/build/contracts/contentAssetStorage.json') + await readFile('node_modules/dkg-evm-module/build/contracts/ContentAssetStorage.json') ) const accountPrivateKeys = JSON.parse( @@ -136,17 +136,20 @@ const testParametersStorageParams = { class LocalBlockchain { constructor(options = {}) { this.logger = options.logger ?? console; + const logging = options.logger ? { + logger: { + log: this.logger.log, + } + } : { + quiet: true, + }; this.port = options.port ?? 7545; this.name = options.name ?? 'ganache'; this.server = Ganache.server({ /* miner: { blockTime: 1, }, */ - logging: { - logger: { - log: console.log, - }, - }, + logging, gas: 20000000, time: new Date(), accounts: accountPrivateKeys.map((account) => ({ diff --git a/test/utilities/dkg-client-helper.mjs b/test/utilities/dkg-client-helper.mjs index 77990789e..52818ae61 100644 --- a/test/utilities/dkg-client-helper.mjs +++ b/test/utilities/dkg-client-helper.mjs @@ -15,7 +15,6 @@ class DkgClientHelper { triplesNumber: 3, chunksNumber: 3, epochsNum: 5, - tokenAmount: 10, maxNumberOfRetries: 5, hashFunctionId: 1, blockchain: { diff --git a/test/utilities/steps-utils.mjs b/test/utilities/steps-utils.mjs index 5185ec389..df62f0a98 100644 --- a/test/utilities/steps-utils.mjs +++ b/test/utilities/steps-utils.mjs @@ -9,7 +9,7 @@ class StepsUtils { } - createNodeConfiguration(blockchain, wallet, managementWallet, nodeIndex, nodeName, rpcPort) { + createNodeConfiguration(blockchain, wallet, managementWallet, nodeIndex, nodeName, rpcPort, sharesTokenName, sharesTokenSymbol) { return { modules: { blockchain: @@ -25,7 +25,9 @@ class StepsUtils { evmOperationalWalletPublicKey: wallet.address, evmOperationalWalletPrivateKey: wallet.privateKey, evmManagementWalletPublicKey: managementWallet.address, - evmManagementPublicKey: managementWallet.address, + evmManagementWalletPrivateKey: managementWallet.privateKey, + sharesTokenName, + sharesTokenSymbol }, }, }, @@ -71,11 +73,11 @@ class StepsUtils { databaseName: `operationaldbnode${nodeIndex}`, }, rpcPort, - appDataPath: `data${nodeIndex}`, + appDataPath: `test-data${nodeIndex}`, graphDatabase: { name: nodeName, }, }; } } -export default StepsUtils; \ No newline at end of file +export default StepsUtils; diff --git a/tools/local-network-setup/generate-config-files.js b/tools/local-network-setup/generate-config-files.js index 80515174a..05783f905 100644 --- a/tools/local-network-setup/generate-config-files.js +++ b/tools/local-network-setup/generate-config-files.js @@ -52,11 +52,6 @@ for (let i = 0; i < numberOfNodes; i += 1) { if (i === 0) { template = bootstrapTemplate; templatePath = bootstrapTemplatePath; - fs.writeFileSync( - path.join(appRootPath.path, appDataPath, LIBP2P_KEY_DIRECTORY, LIBP2P_KEY_FILENAME), - bootstrapTemplate.modules.network.implementation['libp2p-service'].config.privateKey, - ); - console.log('Using the preexisting identity for the first node (bootstrap)'); nodeName = 'bootstrap'; } else { template = dhTemplate;