Skip to content

Commit

Permalink
update integration test after sbt oracle removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill-K-1 committed Feb 4, 2024
1 parent 21c07cc commit 8ea83c5
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 87 deletions.
189 changes: 115 additions & 74 deletions user-verifier/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,100 +13,141 @@ pub fn to_bytes<T: Serialize>(structure: T) -> Result<Vec<u8>, serde_json::Error
serde_json::to_writer(&mut bytes, &structure).map(|_| bytes)
}

pub fn init_human_sbt_issuer_contract<T: web3::Transport>(
pub fn init_human_sbt_contract<T: web3::Transport>(
eth: Eth<T>,
) -> Result<Contract<T>, anyhow::Error> {
// Default address where Human SBT Issuer proxy is deployed at Hardhat local node
let sbt_issuer_address =
ethereum_types::Address::from_str("0x5FC8d32690cc91D4c39d9d3abcBD16989F875707")?;
// Default address where Human SBT proxy is deployed at Hardhat local node
let sbt_address =
ethereum_types::Address::from_str("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512")?;

let abi_bytes = to_bytes(serde_json::json!([
{
"inputs": [
{
"internalType": "address",
"name": "userWallet",
"type": "address"
}
],
"name": "sbtBurn",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "userWallet",
"type": "address"
},
{
"inputs": [
{
"internalType": "address",
"name": "userWallet",
"type": "address"
}
],
"name": "sbtBurn",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
"internalType": "uint256",
"name": "userId",
"type": "uint256"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "signedData",
"type": "bytes"
},
{
"internalType": "uint8",
"name": "v",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "r",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "s",
"type": "bytes32"
}
],
"name": "sbtMint",
"outputs": [],
"stateMutability": "payable",
"type": "function"
"internalType": "uint256",
"name": "expiresAt",
"type": "uint256"
}
],
"name": "sbtMint",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "userWallet",
"type": "address"
}
],
"name": "sbtVerify",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
]))?;

Contract::from_json(eth, sbt_issuer_address, &abi_bytes).map_err(anyhow::Error::from)
Contract::from_json(eth, sbt_address, &abi_bytes).map_err(anyhow::Error::from)
}

pub fn init_sbt_oracle_contract<T: web3::Transport>(
pub fn init_human_sbt_issuer_contract<T: web3::Transport>(
eth: Eth<T>,
) -> Result<Contract<T>, anyhow::Error> {
// Default address where SBT Oracle proxy is deployed at Hardhat local node
let sbt_oracle_address =
ethereum_types::Address::from_str("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512")?;
// Default address where Human SBT Issuer contract is deployed at Hardhat local node
let sbt_issuer_address =
ethereum_types::Address::from_str("0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0")?;

let abi_bytes = to_bytes(serde_json::json!([
{
"inputs": [
{
"internalType": "address",
"name": "sbtAddress",
"type": "address"
},
{
"inputs": [
{
"internalType": "address",
"name": "sbtContract",
"type": "address"
},
{
"internalType": "address",
"name": "userWallet",
"type": "address"
}
],
"name": "sbtVerify",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
"internalType": "address",
"name": "userWallet",
"type": "address"
}
],
"name": "sbtBurn",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "sbtAddress",
"type": "address"
},
{
"internalType": "bytes",
"name": "signedData",
"type": "bytes"
},
{
"internalType": "uint8",
"name": "v",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "r",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "s",
"type": "bytes32"
}
],
"name": "sbtMint",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
]))?;

Contract::from_json(eth, sbt_oracle_address, &abi_bytes).map_err(anyhow::Error::from)
Contract::from_json(eth, sbt_issuer_address, &abi_bytes).map_err(anyhow::Error::from)
}

pub async fn signed_call<T: web3::Transport, P: contract::tokens::Tokenize + Clone>(
Expand Down
35 changes: 22 additions & 13 deletions user-verifier/tests/test_sbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod common;

use assert_matches::assert_matches;
use chrono::Utc;
use ethereum_types::Address;
use jsonrpc_core::Error as RPCError;
use std::str::FromStr;
use uuid::Uuid;
Expand All @@ -14,7 +13,7 @@ use web3::{

use airdao_gov_user_verifier::signer;

use common::{init_human_sbt_issuer_contract, init_sbt_oracle_contract, signed_call};
use common::{init_human_sbt_contract, init_human_sbt_issuer_contract, signed_call};

const ERR_SBT_EXPIRED_OR_NOT_EXIST: &str = "Error: VM Exception while processing transaction: reverted with reason string 'SBT expired or not exist'";
const ERR_SBT_ALREADY_EXIST: &str = "Error: VM Exception while processing transaction: reverted with reason string 'Non-expired Human SBT already exist'";
Expand All @@ -36,9 +35,8 @@ async fn test_sbt() -> Result<(), anyhow::Error> {
let http = web3::transports::Http::new("http://127.0.0.1:8545")?;
let web3_client = web3::Web3::new(http);

let human_sbt_addr = Address::from_str("0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9").unwrap();
let sbt_contract = init_human_sbt_contract(web3_client.eth())?;
let issuer_contract = init_human_sbt_issuer_contract(web3_client.eth())?;
let oracle_contract = init_sbt_oracle_contract(web3_client.eth())?;

// Account #1 private key from Hardhat local node
let signer_private_key =
Expand Down Expand Up @@ -71,7 +69,13 @@ async fn test_sbt() -> Result<(), anyhow::Error> {
signed_call(
&issuer_contract,
"sbtMint",
(signed_data.clone(), req.v, sig_r, sig_s),
(
sbt_contract.address(),
signed_data.clone(),
req.v,
sig_r,
sig_s,
),
&wallet_secret,
)
.await
Expand All @@ -80,18 +84,18 @@ async fn test_sbt() -> Result<(), anyhow::Error> {
let err_already_exist = signed_call(
&issuer_contract,
"sbtMint",
(signed_data, req.v, sig_r, sig_s),
(sbt_contract.address(), signed_data, req.v, sig_r, sig_s),
&wallet_secret,
)
.await
.unwrap_err();
assert_matches!(err_already_exist, ApiError(web3::Error::Rpc(RPCError { message, .. })) if message.as_str() == ERR_SBT_ALREADY_EXIST);

// Verify that Human SBT is minted correctly
let (user_id, _) = oracle_contract
let (user_id, _) = sbt_contract
.query::<(u128, u64), _, _, _>(
"sbtVerify",
(human_sbt_addr, wallet.address()),
wallet.address(),
wallet.address(),
contract::Options::default(),
None,
Expand All @@ -104,15 +108,20 @@ async fn test_sbt() -> Result<(), anyhow::Error> {
);

// Try to burn Human SBT
signed_call(&issuer_contract, "sbtBurn", wallet.address(), &owner_secret)
.await
.unwrap();
signed_call(
&issuer_contract,
"sbtBurn",
(sbt_contract.address(), wallet.address()),
&owner_secret,
)
.await
.unwrap();

// Verify that Human SBT doesn't exist anymore
let err_no_sbt = oracle_contract
let err_no_sbt = sbt_contract
.query::<(u128, u64), _, _, _>(
"sbtVerify",
(human_sbt_addr, wallet.address()),
wallet.address(),
wallet.address(),
contract::Options::default(),
None,
Expand Down

0 comments on commit 8ea83c5

Please sign in to comment.