Created
March 2, 2022 16:30
-
-
Save yann300/0bc9938ab60fdab62589d891885e05fc to your computer and use it in GitHub Desktop.
should_fails.js
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
// Right click on the script name and hit "Run" to execute | |
const { expect } = require("chai"); | |
const { ethers } = require("hardhat"); | |
describe("Storage", function () { | |
it("Should Deploy storage and call functions", async function () { | |
try { | |
// function getContractFactoryFromArtifact(artifact: Artifact, signer?: ethers.Signer): Promise<ethers.ContractFactory>; | |
// function getContractFactoryFromArtifact(artifact: Artifact, factoryOptions: FactoryOptions): Promise<ethers.ContractFactory>; | |
const metadata = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/Storage.json')) | |
/* | |
export interface Artifact { | |
_format: string; | |
contractName: string; | |
sourceName: string; | |
abi: any[]; | |
bytecode: string; // "0x"-prefixed hex string | |
deployedBytecode: string; // "0x"-prefixed hex string | |
linkReferences: LinkReferences; | |
deployedLinkReferences: LinkReferences; | |
} | |
*/ | |
/* | |
interface Libraries { | |
[libraryName: string]: string; | |
} | |
interface FactoryOptions { | |
signer?: ethers.Signer; | |
libraries?: Libraries; | |
} | |
*/ | |
const artifact = { | |
contractName: '', | |
sourceName: 'contracts/1_Storage.sol', | |
abi: metadata.abi, | |
bytecode: '0x' + metadata.data.bytecode.object, | |
deployedBytecode: '0x' + metadata.data.deployedBytecode.object, | |
linkReferences: metadata.data.bytecode.linkReferences, | |
deployedLinkReferences: metadata.data.deployedBytecode.linkReferences, | |
} | |
const options = { | |
libraries: metadata.deploy['VM:-'].linkReferences['contracts/1_Storage.sol'] | |
} | |
// console.log(options) | |
const factory = await ethers.getContractFactoryFromArtifact(artifact, options) | |
const storage = await factory.deploy(); | |
await storage.deployed(); | |
expect((await storage.retrieve()).toString()).to.equal('0') | |
const storeValue = await storage.store(333); | |
// wait until the transaction is mined | |
await storeValue.wait(); | |
expect((await storage.retrieve()).toString()).to.equal('3s33') | |
try { | |
// console.log(await storage.getFromLib()) | |
} catch (e) { | |
console.log(e) | |
} | |
// expect((await storage.getFromLib()).toString()).to.equal('34'); | |
} catch (e) { | |
console.log(e.message) | |
} | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment