-
Notifications
You must be signed in to change notification settings - Fork 59
SPIKE: Protocol 28 (CAP-0084) #1700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 14 commits
f0eafaa
fa5473b
45162cd
6199f74
f4a995c
83a01f3
84bc47c
ba50c6d
55e3098
4b4ec35
708b3c4
569a74c
08d56e0
b4aec4e
128d710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| " 0 begin": "cpu:0, mem:0, prngs:-/-, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-", | ||
| " 1 call get_address_from_muxed_address(MuxedAddress(obj#1))": "cpu:442, mem:80, objs:-/1@a53ac37b", | ||
| " 2 ret get_address_from_muxed_address -> Ok(Address(obj#3))": "cpu:1110, mem:160, objs:-/2@4b6987b0", | ||
| " 3 call get_id_from_muxed_address(MuxedAddress(obj#1))": "", | ||
| " 4 ret get_id_from_muxed_address -> Ok(U64(456))": "cpu:1230", | ||
| " 5 end": "cpu:1338, mem:160, prngs:-/-, objs:-/2@4b6987b0, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-" | ||
| } |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| " 0 begin": "cpu:14285, mem:0, prngs:-/9b4a753, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-", | ||
| " 1 end": "cpu:14895, mem:80, prngs:-/9b4a753, objs:-/1@d3ad1bcd, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,26 @@ pub(crate) fn contract_id_to_address(host: &Host, contract_id: [u8; 32]) -> Addr | |
| .unwrap() | ||
| } | ||
|
|
||
| // CAP-0084: build a muxed contract address (`ScAddress::MuxedContract`) wrapping | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this comment is redundant; it makes no sense to point out CAPs beyond the unit test modules, and this is a test utility with a self-evident interface. |
||
| // the given contract id and multiplexing id, mirroring `TestSigner::muxed_address` | ||
| // for accounts. | ||
| pub(crate) fn muxed_contract_address( | ||
| host: &Host, | ||
| contract_id: [u8; 32], | ||
| mux_id: u64, | ||
| ) -> MuxedAddress { | ||
| use soroban_env_common::xdr::MuxedContract; | ||
| let sc_address = ScAddress::MuxedContract(MuxedContract { | ||
| id: mux_id, | ||
| contract_id: ContractId(Hash(contract_id)), | ||
| }); | ||
| MuxedAddress::try_from_val( | ||
| host, | ||
| &host.add_host_object(MuxedScAddress(sc_address)).unwrap(), | ||
| ) | ||
| .unwrap() | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| pub(crate) enum TestSigner { | ||
| AccountInvoker(AccountId), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,13 @@ fn display_address(addr: &ScAddress, f: &mut std::fmt::Formatter<'_>) -> std::fm | |
| }; | ||
| write!(f, "{}", strkey) | ||
| } | ||
| // CAP-0084: muxed contracts have no canonical strkey form yet, so this | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is misleading (because muxed addresses may appear in events), and also is generally redundant. |
||
| // is a diagnostic-only rendering. In practice muxed contract addresses | ||
| // are de-muxed before they reach events, making this arm unreachable. | ||
| ScAddress::MuxedContract(muxed_contract) => { | ||
| let strkey = stellar_strkey::Contract(muxed_contract.contract_id.0 .0); | ||
| write!(f, "{}:{}", strkey, muxed_contract.id) | ||
| } | ||
| // Note, that claimable balance and liquidity pool types can't normally | ||
| // appear in host, so we have the proper rendering for these here just | ||
| // for consistency (similar to e.g. non-representable ScVal types). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,31 @@ fn test_muxed_address_to_components_conversion() { | |
| assert_eq!(mux_id_val, ScVal::U64(123)); | ||
| } | ||
|
|
||
| // CAP-0084: `get_address_from_muxed_address` / `get_id_from_muxed_address` on a | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is redundant, we could optionally add cap84 to the test name itself |
||
| // muxed contract return the underlying contract address and the mux id. | ||
| #[test] | ||
| fn test_muxed_contract_to_components_conversion() { | ||
| use crate::xdr::MuxedContract; | ||
| let host = observe_host!(Host::test_host()); | ||
| let muxed_address_obj = host | ||
| .add_host_object(MuxedScAddress(ScAddress::MuxedContract(MuxedContract { | ||
| id: 456, | ||
| contract_id: ContractId(Hash([20; 32])), | ||
| }))) | ||
| .unwrap(); | ||
| let address = host | ||
| .get_address_from_muxed_address(muxed_address_obj) | ||
| .unwrap(); | ||
| let mux_id = host.get_id_from_muxed_address(muxed_address_obj).unwrap(); | ||
| let address_val = host.from_host_val(address.into()).unwrap(); | ||
| let mux_id_val = host.from_host_val(mux_id.into()).unwrap(); | ||
| assert_eq!( | ||
| address_val, | ||
| ScVal::Address(ScAddress::Contract(ContractId(Hash([20; 32])))) | ||
| ); | ||
| assert_eq!(mux_id_val, ScVal::U64(456)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_invalid_muxed_address_object_conversions() { | ||
| let host = observe_host!(Host::test_host()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be removed