|
|
@ -196,7 +196,7 @@ module.exports = { |
|
|
|
'Should run a script right after compilation #group5': function (browser: NightwatchBrowser) { |
|
|
|
'Should run a script right after compilation #group5': function (browser: NightwatchBrowser) { |
|
|
|
browser |
|
|
|
browser |
|
|
|
.addFile('storage.sol', { content: scriptAutoExec.contract } ) |
|
|
|
.addFile('storage.sol', { content: scriptAutoExec.contract } ) |
|
|
|
.addFile('autoExec.js', { content: scriptAutoExec.script } ) |
|
|
|
.addFile('scripts/deploy_storage.js', { content: scriptAutoExec.script } ) |
|
|
|
.openFile('storage.sol') |
|
|
|
.openFile('storage.sol') |
|
|
|
.sendKeys('body', [browser.Keys.CONTROL, 'e']) |
|
|
|
.sendKeys('body', [browser.Keys.CONTROL, 'e']) |
|
|
|
.journalChildIncludes('147', { shouldHaveOnlyOneOccurence: true }) |
|
|
|
.journalChildIncludes('147', { shouldHaveOnlyOneOccurence: true }) |
|
|
@ -495,111 +495,113 @@ contract OwnerTest { |
|
|
|
}` |
|
|
|
}` |
|
|
|
|
|
|
|
|
|
|
|
const scriptAutoExec = { |
|
|
|
const scriptAutoExec = { |
|
|
|
contract: ` |
|
|
|
contract: `// SPDX-License-Identifier: GPL-3.0
|
|
|
|
|
|
|
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
|
|
|
pragma solidity >=0.7.0 <0.9.0; |
|
|
|
|
|
|
|
|
|
|
|
pragma solidity >=0.7.0 <0.9.0; |
|
|
|
library lib { |
|
|
|
|
|
|
|
function test () public view returns (uint) { |
|
|
|
|
|
|
|
|
|
|
|
library lib { |
|
|
|
return 147; |
|
|
|
function test () public view returns (uint) { |
|
|
|
} |
|
|
|
return 147; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @title Storage |
|
|
|
|
|
|
|
* @dev Store & retrieve value inr a variable |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
contract Storage { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint256 number; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @dev Store valrue in variable |
|
|
|
|
|
|
|
* @param num value to store |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function store(uint256 num) public {
|
|
|
|
|
|
|
|
number = num;
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @dev Return value
|
|
|
|
|
|
|
|
* @return value of 'number' |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function retrieve() public view returns (uint256){ |
|
|
|
|
|
|
|
return number; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getFromLib() public view returns (uint) { |
|
|
|
/** |
|
|
|
return lib.test(); |
|
|
|
* @title Storage |
|
|
|
} |
|
|
|
* @dev Store & retrieve value inr a variable |
|
|
|
}`,
|
|
|
|
* @custom:dev-run-script ./scripts/deploy_storage.js |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
contract Storage { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint256 number; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @dev Store valrue in variable |
|
|
|
|
|
|
|
* @param num value to store |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function store(uint256 num) public { |
|
|
|
|
|
|
|
number = num;
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @dev Return value
|
|
|
|
|
|
|
|
* @return value of 'number' |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function retrieve() public view returns (uint256){ |
|
|
|
|
|
|
|
return number; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getFromLib() public view returns (uint) { |
|
|
|
|
|
|
|
return lib.test(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
`,
|
|
|
|
script: ` |
|
|
|
script: ` |
|
|
|
// Right click on the script name and hit "Run" to execute
|
|
|
|
// Right click on the script name and hit "Run" to execute
|
|
|
|
const { expect } = require("chai"); |
|
|
|
const { expect } = require("chai"); |
|
|
|
const { ethers } = require("hardhat"); |
|
|
|
const { ethers } = require("hardhat"); |
|
|
|
|
|
|
|
|
|
|
|
(async () => { |
|
|
|
(async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// function getContractFactoryFromArtifact(artifact: Artifact, signer?: ethers.Signer): Promise<ethers.ContractFactory>;
|
|
|
|
// function getContractFactoryFromArtifact(artifact: Artifact, signer?: ethers.Signer): Promise<ethers.ContractFactory>;
|
|
|
|
|
|
|
|
|
|
|
|
// function getContractFactoryFromArtifact(artifact: Artifact, factoryOptions: FactoryOptions): Promise<ethers.ContractFactory>;
|
|
|
|
// function getContractFactoryFromArtifact(artifact: Artifact, factoryOptions: FactoryOptions): Promise<ethers.ContractFactory>;
|
|
|
|
|
|
|
|
|
|
|
|
const metadataLib = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/lib.json')) |
|
|
|
const metadataLib = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/lib.json')) |
|
|
|
console.log('deploying lib:') |
|
|
|
console.log('deploying lib:') |
|
|
|
|
|
|
|
|
|
|
|
const artifactLib = { |
|
|
|
const artifactLib = { |
|
|
|
contractName: 'Lib', |
|
|
|
contractName: 'Lib', |
|
|
|
sourceName: 'contracts/1_Storage.sol', |
|
|
|
sourceName: 'contracts/1_Storage.sol', |
|
|
|
abi: metadataLib.abi, |
|
|
|
abi: metadataLib.abi, |
|
|
|
bytecode: '0x' + metadataLib.data.bytecode.object, |
|
|
|
bytecode: '0x' + metadataLib.data.bytecode.object, |
|
|
|
deployedBytecode: '0x' + metadataLib.data.deployedBytecode.object, |
|
|
|
deployedBytecode: '0x' + metadataLib.data.deployedBytecode.object, |
|
|
|
linkReferences: metadataLib.data.bytecode.linkReferences, |
|
|
|
linkReferences: metadataLib.data.bytecode.linkReferences, |
|
|
|
deployedLinkReferences: metadataLib.data.deployedBytecode.linkReferences, |
|
|
|
deployedLinkReferences: metadataLib.data.deployedBytecode.linkReferences, |
|
|
|
} |
|
|
|
} |
|
|
|
const optionsLib = {} |
|
|
|
const optionsLib = {} |
|
|
|
|
|
|
|
|
|
|
|
const factoryLib = await ethers.getContractFactoryFromArtifact(artifactLib, optionsLib) |
|
|
|
const factoryLib = await ethers.getContractFactoryFromArtifact(artifactLib, optionsLib) |
|
|
|
|
|
|
|
|
|
|
|
const lib = await factoryLib.deploy(); |
|
|
|
const lib = await factoryLib.deploy(); |
|
|
|
|
|
|
|
|
|
|
|
await lib.deployed() |
|
|
|
await lib.deployed() |
|
|
|
|
|
|
|
|
|
|
|
console.log('lib deployed', lib.address) |
|
|
|
console.log('lib deployed', lib.address) |
|
|
|
|
|
|
|
|
|
|
|
const metadata = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/Storage.json')) |
|
|
|
const metadata = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/Storage.json')) |
|
|
|
const artifact = { |
|
|
|
const artifact = { |
|
|
|
contractName: 'Storage', |
|
|
|
contractName: 'Storage', |
|
|
|
sourceName: 'contracts/1_Storage.sol', |
|
|
|
sourceName: 'contracts/1_Storage.sol', |
|
|
|
abi: metadata.abi, |
|
|
|
abi: metadata.abi, |
|
|
|
bytecode: '0x' + metadata.data.bytecode.object, |
|
|
|
bytecode: '0x' + metadata.data.bytecode.object, |
|
|
|
deployedBytecode: '0x' + metadata.data.deployedBytecode.object, |
|
|
|
deployedBytecode: '0x' + metadata.data.deployedBytecode.object, |
|
|
|
linkReferences: metadata.data.bytecode.linkReferences, |
|
|
|
linkReferences: metadata.data.bytecode.linkReferences, |
|
|
|
deployedLinkReferences: metadata.data.deployedBytecode.linkReferences, |
|
|
|
deployedLinkReferences: metadata.data.deployedBytecode.linkReferences, |
|
|
|
} |
|
|
|
} |
|
|
|
const options = { |
|
|
|
const options = { |
|
|
|
libraries: {
|
|
|
|
libraries: {
|
|
|
|
'lib': lib.address |
|
|
|
'lib': lib.address |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const factory = await ethers.getContractFactoryFromArtifact(artifact, options) |
|
|
|
const factory = await ethers.getContractFactoryFromArtifact(artifact, options) |
|
|
|
|
|
|
|
|
|
|
|
const storage = await factory.deploy(); |
|
|
|
const storage = await factory.deploy(); |
|
|
|
|
|
|
|
|
|
|
|
await storage.deployed() |
|
|
|
await storage.deployed() |
|
|
|
|
|
|
|
|
|
|
|
const storeValue = await storage.store(333); |
|
|
|
const storeValue = await storage.store(333); |
|
|
|
|
|
|
|
|
|
|
|
// wait until the transaction is mined
|
|
|
|
// wait until the transaction is mined
|
|
|
|
await storeValue.wait(); |
|
|
|
await storeValue.wait(); |
|
|
|
|
|
|
|
|
|
|
|
console.log((await storage.getFromLib()).toString()) |
|
|
|
console.log((await storage.getFromLib()).toString()) |
|
|
|
// expect((await storage.getFromLib()).toString()).to.equal('34');
|
|
|
|
// expect((await storage.getFromLib()).toString()).to.equal('34');
|
|
|
|
|
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
console.error(e.message) |
|
|
|
console.error(e.message) |
|
|
|
} |
|
|
|
} |
|
|
|
})() |
|
|
|
})() |
|
|
|
` |
|
|
|
` |
|
|
|
} |
|
|
|
} |