use proposal_derive::Proposal;
use crate::ProposalHeader;
#[derive(
Proposal,
Debug,
Copy,
Clone,
PartialEq,
Eq,
Hash,
serde::Serialize,
serde::Deserialize,
)]
#[proposal(
function_sig = "function setDailyWithdrawalLimit(uint256 _limit, uint32 _nonce)"
)]
pub struct SetDailyWithdrawalLimitProposal {
header: ProposalHeader,
daily_withdrawal_limit: [u8; 32],
}
#[cfg(test)]
mod tests {
use crate::{
FunctionSignature, Nonce, ResourceId, TargetSystem, TypedChainId,
};
use super::*;
#[test]
fn encode() {
let target_system = TargetSystem::new_contract_address(
hex_literal::hex!("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
);
let target_chain = TypedChainId::Evm(4);
let resource_id = ResourceId::new(target_system, target_chain);
let function_signature =
FunctionSignature::new(hex_literal::hex!("cafebabe"));
let nonce = Nonce::from(0x0001);
let header =
ProposalHeader::new(resource_id, function_signature, nonce);
let limit = hex_literal::hex!(
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
);
let proposal = SetDailyWithdrawalLimitProposal::new(header, limit);
let bytes = crate::to_vec(&proposal).unwrap();
let expected = hex_literal::hex!(
"000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa010000000004"
"cafebabe00000001000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
);
assert_eq!(bytes, expected);
}
#[test]
fn decode() {
let bytes = hex_literal::hex!(
"000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa010000000004"
"cafebabe00000001000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
);
let proposal =
crate::from_slice::<SetDailyWithdrawalLimitProposal>(&bytes)
.unwrap();
let header = proposal.header();
let resource_id = header.resource_id();
let target_system = resource_id.target_system();
let target_chain = resource_id.typed_chain_id();
let function_signature = header.function_signature();
let nonce = header.nonce();
let limit = proposal.daily_withdrawal_limit();
assert_eq!(
target_system,
TargetSystem::new_contract_address(hex_literal::hex!(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
))
);
assert_eq!(target_chain, TypedChainId::Evm(4));
assert_eq!(
function_signature,
FunctionSignature::new(hex_literal::hex!("cafebabe"))
);
assert_eq!(nonce, Nonce::from(0x0001));
assert_eq!(
limit,
&hex_literal::hex!(
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
)
);
}
}