accountant: address comments from #2513
This commit is contained in:
parent
0f123dedb1
commit
6324a239f9
|
@ -334,21 +334,15 @@ fn handle_vaa(
|
|||
let mut evt = if body.emitter_chain == Chain::Solana
|
||||
&& body.emitter_address == wormhole::GOVERNANCE_EMITTER
|
||||
{
|
||||
let mut module = [0u8; 32];
|
||||
module.clone_from_slice(&body.payload.get()[..32]);
|
||||
|
||||
if let Ok(govpacket) = serde_wormhole::from_slice::<token::GovernancePacket>(body.payload) {
|
||||
handle_token_governance_vaa(deps.branch(), body.with_payload(govpacket))?
|
||||
} else if let Ok(govpacket) =
|
||||
serde_wormhole::from_slice::<accountant_module::GovernancePacket>(body.payload)
|
||||
{
|
||||
handle_accountant_moduleernance_vaa(deps.branch(), info, body.with_payload(govpacket))?
|
||||
handle_accountant_governance_vaa(deps.branch(), info, body.with_payload(govpacket))?
|
||||
} else {
|
||||
bail!("Unknown governance module")
|
||||
}
|
||||
|
||||
// let govpacket: GovernancePacket =
|
||||
// .context("failed to parse governance packet")?;
|
||||
} else {
|
||||
let msg = serde_wormhole::from_slice(body.payload)
|
||||
.context("failed to parse tokenbridge message")?;
|
||||
|
@ -370,7 +364,7 @@ fn handle_token_governance_vaa(
|
|||
) -> anyhow::Result<Event> {
|
||||
ensure!(
|
||||
body.payload.chain == Chain::Any || body.payload.chain == Chain::Wormchain,
|
||||
"this governance VAA is for another chain"
|
||||
"this token governance VAA is for another chain"
|
||||
);
|
||||
|
||||
match body.payload.action {
|
||||
|
@ -393,14 +387,14 @@ fn handle_token_governance_vaa(
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_accountant_moduleernance_vaa(
|
||||
fn handle_accountant_governance_vaa(
|
||||
deps: DepsMut<WormholeQuery>,
|
||||
info: &MessageInfo,
|
||||
body: Body<accountant_module::GovernancePacket>,
|
||||
) -> anyhow::Result<Event> {
|
||||
ensure!(
|
||||
body.payload.chain == Chain::Any || body.payload.chain == Chain::Wormchain,
|
||||
"this governance VAA is for another chain"
|
||||
body.payload.chain == Chain::Wormchain,
|
||||
"this accountant governance VAA is for another chain"
|
||||
);
|
||||
|
||||
match body.payload.action {
|
||||
|
|
|
@ -92,7 +92,7 @@ fn wrong_target() {
|
|||
.submit_vaas(vec![data])
|
||||
.expect_err("successfully executed chain registration VAA for different chain");
|
||||
assert_eq!(
|
||||
"this governance vaa is for another chain",
|
||||
"this token governance vaa is for another chain",
|
||||
err.root_cause().to_string().to_lowercase()
|
||||
);
|
||||
}
|
||||
|
@ -102,7 +102,6 @@ fn non_governance_chain() {
|
|||
let (wh, mut contract) = proper_instantiate();
|
||||
|
||||
let mut body = create_vaa_body();
|
||||
body.payload.chain = Chain::Solana;
|
||||
body.emitter_chain = Chain::Fantom;
|
||||
|
||||
let (_, data) = sign_vaa_body(&wh, body);
|
||||
|
@ -110,8 +109,12 @@ fn non_governance_chain() {
|
|||
.submit_vaas(vec![data])
|
||||
.expect_err("successfully executed chain registration with non-governance chain");
|
||||
|
||||
// This tries to parse as a normal token bridge vaa and fails. Not sure how best to differentiate from a governance message.
|
||||
_ = err;
|
||||
// A governance message with wrong chain or emitter will be parsed as a token bridge message
|
||||
assert!(err
|
||||
.source()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.contains("failed to parse tokenbridge message",));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -126,8 +129,12 @@ fn non_governance_emitter() {
|
|||
.submit_vaas(vec![data])
|
||||
.expect_err("successfully executed chain registration with non-governance emitter");
|
||||
|
||||
// This tries to parse as a normal token bridge vaa and fails. Not sure how best to differentiate from a governance message.
|
||||
_ = err;
|
||||
// A governance message with wrong chain or emitter will be parsed as a token bridge message
|
||||
assert!(err
|
||||
.source()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.contains("failed to parse tokenbridge message",));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -98,7 +98,7 @@ impl Contract {
|
|||
sequence: self.sequence,
|
||||
consistency_level: 0,
|
||||
payload: accountant_module::GovernancePacket {
|
||||
chain: Chain::Any,
|
||||
chain: Chain::Wormchain,
|
||||
action: accountant_module::Action::ModifyBalance {
|
||||
sequence,
|
||||
chain_id,
|
||||
|
|
|
@ -146,7 +146,7 @@ func tokenBridgeRegisterChain(req *nodev1.BridgeRegisterChain, timestamp time.Ti
|
|||
return v, nil
|
||||
}
|
||||
|
||||
// tokenBridgeModifyBalance converts a nodev1.TokenBridgeModifyBalance message to its canonical VAA representation.
|
||||
// accountantModifyBalance converts a nodev1.AccountantModifyBalance message to its canonical VAA representation.
|
||||
// Returns an error if the data is invalid.
|
||||
func accountantModifyBalance(req *nodev1.AccountantModifyBalance, timestamp time.Time, guardianSetIndex uint32, nonce uint32, sequence uint64) (*vaa.VAA, error) {
|
||||
if req.TargetChainId > math.MaxUint16 {
|
||||
|
|
|
@ -233,7 +233,7 @@ mod governance_packet_impl {
|
|||
}
|
||||
v => {
|
||||
return Err(Error::custom(format_args!(
|
||||
"invalid value {v}, expected one of 1, 2"
|
||||
"invalid value {v}, expected one of 1"
|
||||
)))
|
||||
}
|
||||
};
|
||||
|
@ -314,7 +314,7 @@ mod governance_packet_impl {
|
|||
}
|
||||
v => {
|
||||
return Err(Error::custom(format_args!(
|
||||
"invalid action: {v}, expected one of: 1, 2"
|
||||
"invalid action: {v}, expected one of: 1"
|
||||
)))
|
||||
}
|
||||
};
|
||||
|
@ -378,8 +378,8 @@ mod test {
|
|||
0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
|
||||
0x31, 0x31, 0x31, 0x31, // reason
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x41,
|
||||
0x42, 0x42, 0x43, 0x43,
|
||||
];
|
||||
|
||||
let vaa = Vaa {
|
||||
|
@ -410,7 +410,7 @@ mod test {
|
|||
token_address: Address([0x32u8; 32]),
|
||||
kind: ModificationKind::Add,
|
||||
amount: Amount([0x31u8; 32]),
|
||||
reason: "".into(),
|
||||
reason: "AABBCC".into(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -371,7 +371,7 @@ mod governance_packet_impl {
|
|||
}
|
||||
v => {
|
||||
return Err(Error::custom(format_args!(
|
||||
"invalid value: {v}, expected one of 1, 2, 3"
|
||||
"invalid value: {v}, expected one of 1, 2"
|
||||
)))
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue