Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
test: add test to check that abi_str is in human readable format
Browse files Browse the repository at this point in the history
  • Loading branch information
thasarito committed Dec 26, 2021
1 parent 8c63eef commit 42647d6
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions ethers-contract/ethers-contract-abigen/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,74 @@ fn parse_abi(abi_str: &str) -> Result<(Abi, bool, AbiParser)> {
};
Ok(res)
}


#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_abi_str_is_human_readable() {
let abi_str = r#"{
"abi": [
{
"type": "function",
"name": "allowance",
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"constant": false,
"stateMutability": "view"
},
{
"type": "function",
"name": "approve",
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"constant": false,
"stateMutability": "nonpayable"
}
],
"bin": "0x",
"bin-runtime": "0x"
}"#;

let (abi, _, _) = parse_abi(&abi_str).unwrap();
let abi_str = serde_json::to_string(&abi).context("fail to serialize abi to json").unwrap();

assert!(&abi_str.starts_with('['));
}
}

0 comments on commit 42647d6

Please sign in to comment.