Skip to content

Commit

Permalink
add spec for event signature
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningRay committed Jun 11, 2024
1 parent 505f48d commit 2358fa6
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/eth/abi/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
expect(signature).to eq "Transfer(address,address,uint256)"
end


it "generates transfer function signature" do
abi = erc20_abi.find { |i| i["type"] == "function" && i["name"] == "transfer" }
signature = Abi::Event.signature(abi)
Expand Down
80 changes: 80 additions & 0 deletions spec/eth/contract/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,85 @@
expect(contract.events[1].signature).to eq("1f3a0e41bf4d8306f04763663bf025d1824a391571ce3a07186a195f8c4cfd3c")
expect(contract.events[1].event_string).to eq("killed()")
end

it "generates signature for event with tuple params" do
event = Eth::Contract::Event.new({
"anonymous" => false,
"inputs" => [
{
"components" => [
{
"internalType" => "uint256",
"name" => "topicId",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "proposalId",
"type" => "uint256"
},
{
"internalType" => "string",
"name" => "name",
"type" => "string"
},
{
"internalType" => "string",
"name" => "symbol",
"type" => "string"
},
{
"internalType" => "uint256",
"name" => "duration",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "totalSupply",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "miniStakeValue",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "maxStakeValue",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "maxParticipants",
"type" => "uint256"
},
{
"internalType" => "uint256",
"name" => "whitelistIndex",
"type" => "uint256"
},
{
"internalType" => "address",
"name" => "proposer",
"type" => "address"
},
{
"internalType" => "bool",
"name" => "useWhitelist",
"type" => "bool"
}
],
"indexed" => false,
"internalType" => "struct VoteContract.ProposalCreatedParams",
"name" => "params",
"type" => "tuple"
}
],
"name" => "ProposalCreated",
"type" => "event"
})
expect(event.event_string).to eq('ProposalCreated((uint256,uint256,string,string,uint256,uint256,uint256,uint256,uint256,uint256,address,bool))')
expect(event.signature).to eq('4449031b77cbe261580701c097fb63211e768f685581e616330dfff20493536c')
end
end
end

0 comments on commit 2358fa6

Please sign in to comment.