Created
March 22, 2022 00:57
-
-
Save swkim109/8e13fd9ef88069c009985e5b3bb426b7 to your computer and use it in GitHub Desktop.
JS Test in Remix
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
//SPDX-License-Identifier:MIT | |
pragma solidity ^0.8.0; | |
contract Greeter { | |
struct Member { | |
uint256 id; | |
string name; | |
} | |
event Hello(Member indexed u); | |
event Hello2(uint8[5] indexed u); | |
event Hello3(string indexed u); | |
function greet() public pure returns (string memory){ | |
return "Hello, World!"; | |
} | |
function f() external { | |
Member memory u; | |
u.id = 100; | |
u.name = "Kate"; | |
emit Hello(u); | |
} | |
function g() external { | |
emit Hello3("Kate"); | |
} | |
} | |
// 0x92cc18b6be7cc85cd227e7feb4bc7f156c2043ffd750befaae93591b9a4aac2b [100, "Kate"] | |
// 0x5917e5a395fb9b454434de59651d36822a9e29c5ec57474df3e67937b969460c [1,2,3,4,5] |
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
const { expect } = require("chai"); | |
const iface = new ethers.utils.Interface([ | |
"event Hello(tuple(uint256, string) indexed u)" | |
]); | |
const targetHash = "0x92cc18b6be7cc85cd227e7feb4bc7f156c2043ffd750befaae93591b9a4aac2b"; | |
describe("Greeter", function () { | |
it("Hello event should match the topic hash", async function () { | |
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'examples/artifacts/Greeter.json')); | |
const signers = await ethers.getSigners(); | |
let Greeter = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signers[0]); | |
let c = await Greeter.deploy(); | |
const tx = await c.f(); // transaction | |
const result = await tx.wait(); // receipt | |
//console.log(result.logs[0]); | |
const eventLog = iface.parseLog(result.logs[0]); | |
console.log(eventLog.args[0].hash); | |
expect(targetHash).to.equal(eventLog.args[0].hash); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment