Skip to content

Commit 2ede478

Browse files
core: add events for allow-list (#103)
## Description This PR adds event for allow-list updates (`handle_add_to_allowlist`, `handle_remove_from_allowlist`) Fixes #102 ## Checklist - [x] I have updated the [docs/SPEC.md](https://github.com/babylonlabs-io/rollup-bsn-contracts/blob/main/docs/SPEC.md) file if this change affects the specification - [x] I have updated the schema by running `cargo gen-schema`
1 parent 771a5bb commit 2ede478

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3939

4040
### State and API breaking
4141

42-
* [82](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/108) core:
42+
* [#82](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/108) core:
4343
add allow-list to instantiate arg
44-
* [97](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/97) feat:
44+
* [#97](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/97) feat:
4545
versioning of FP allowlist
46-
* [100](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/100) chore:
46+
* [#100](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/100) chore:
4747
add query to fetch highest voted height
4848

4949
### Improvements
5050

5151
* [#108](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/91) feat:
5252
optimize public key handling by using bytes instead of hex
53+
* [#103](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/103) core:
54+
add events for allow-list
5355
* [#91](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/91) feat:
5456
optimize public key handling by using bytes instead of hex
5557
* [#98](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/98) feat:

contracts/finality/src/contract.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,59 @@ pub(crate) mod tests {
15331533
}
15341534
}
15351535

1536+
#[test]
1537+
fn test_allowlist_events() {
1538+
let mut deps = mock_deps_babylon();
1539+
let admin = deps.api.addr_make(INIT_ADMIN);
1540+
let admin_info = message_info(&admin, &[]);
1541+
1542+
// Instantiate contract
1543+
let instantiate_msg = InstantiateMsg {
1544+
admin: admin.to_string(),
1545+
bsn_id: "test-bsn-id".to_string(),
1546+
min_pub_rand: 100,
1547+
max_msgs_per_interval: MAX_MSGS_PER_INTERVAL,
1548+
rate_limiting_interval: RATE_LIMITING_INTERVAL,
1549+
bsn_activation_height: 0,
1550+
finality_signature_interval: 1,
1551+
allowed_finality_providers: None,
1552+
};
1553+
let info = message_info(&deps.api.addr_make(CREATOR), &[]);
1554+
instantiate(deps.as_mut(), mock_env(), info, instantiate_msg).unwrap();
1555+
1556+
// Test add to allowlist event
1557+
let fp_keys = vec![
1558+
"02a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7".to_string(),
1559+
"c51bff10d544a2daa9e57fa00b70eb4b61d01a646c040fd0c7c1f69fd8289c8ac3".to_string(),
1560+
];
1561+
let add_msg = ExecuteMsg::AddToAllowlist {
1562+
fp_pubkey_hex_list: fp_keys.clone(),
1563+
};
1564+
let res = execute(deps.as_mut(), mock_env(), admin_info.clone(), add_msg).unwrap();
1565+
1566+
// Check event was emitted
1567+
assert_eq!(res.events.len(), 1);
1568+
let event = &res.events[0];
1569+
assert_eq!(event.ty, "add_to_allowlist");
1570+
assert_eq!(event.attributes.len(), 1);
1571+
assert_eq!(event.attributes[0].key, "fp_pubkeys");
1572+
assert_eq!(event.attributes[0].value, fp_keys.join(","));
1573+
1574+
// Test remove from allowlist event
1575+
let remove_msg = ExecuteMsg::RemoveFromAllowlist {
1576+
fp_pubkey_hex_list: vec![fp_keys[0].clone()],
1577+
};
1578+
let res = execute(deps.as_mut(), mock_env(), admin_info, remove_msg).unwrap();
1579+
1580+
// Check event was emitted
1581+
assert_eq!(res.events.len(), 1);
1582+
let event = &res.events[0];
1583+
assert_eq!(event.ty, "remove_from_allowlist");
1584+
assert_eq!(event.attributes.len(), 1);
1585+
assert_eq!(event.attributes[0].key, "fp_pubkeys");
1586+
assert_eq!(event.attributes[0].value, fp_keys[0].clone());
1587+
}
1588+
15361589
#[test]
15371590
fn test_instantiate_allowlist_event() {
15381591
let mut deps = mock_deps_babylon();

contracts/finality/src/exec/allowlist.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response};
1+
use cosmwasm_std::{DepsMut, Env, Event, MessageInfo, Response};
22

33
use crate::error::ContractError;
44
use crate::msg::BabylonMsg;
@@ -37,7 +37,11 @@ pub fn handle_add_to_allowlist(
3737

3838
add_finality_providers_to_allowlist(deps.storage, &fp_btc_pk_bytes_list, env.block.height)?;
3939

40+
let event =
41+
Event::new("add_to_allowlist").add_attribute("fp_pubkeys", fp_pubkey_hex_list.join(","));
42+
4043
Ok(Response::new()
44+
.add_event(event)
4145
.add_attribute("action", "add_to_allowlist")
4246
.add_attribute("num_added", fp_pubkey_hex_list.len().to_string()))
4347
}
@@ -75,7 +79,11 @@ pub fn handle_remove_from_allowlist(
7579
env.block.height,
7680
)?;
7781

82+
let event = Event::new("remove_from_allowlist")
83+
.add_attribute("fp_pubkeys", fp_pubkey_hex_list.join(","));
84+
7885
Ok(Response::new()
86+
.add_event(event)
7987
.add_attribute("action", "remove_from_allowlist")
8088
.add_attribute("num_removed", fp_pubkey_hex_list.len().to_string()))
8189
}

0 commit comments

Comments
 (0)