-
Notifications
You must be signed in to change notification settings - Fork 1
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
Account locker in manifest summary encountered entities #213
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1e111e2
Add locker execution summary test
sergiupuhalschi-rdx 5789df3
Add locker address to manifest encountered entities
sergiupuhalschi-rdx 816bc9c
Version bump
sergiupuhalschi-rdx 6e73c14
Add kotlin and swift
sergiupuhalschi-rdx 591b4cf
Add swift tests
sergiupuhalschi-rdx 9e402dc
Potential fix for disk space issue in kotlin tests workflow
sergiupuhalschi-rdx 41f6b7a
Update kotlin workflow
sergiupuhalschi-rdx a22a112
Update kotlin test workflow
sergiupuhalschi-rdx ce241d6
Revert "Update kotlin test workflow"
sergiupuhalschi-rdx e42b281
Name refactoring
sergiupuhalschi-rdx 354e519
Improve kotlin coverage
sergiupuhalschi-rdx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
...Sources/Sargon/Extensions/Methods/Address/ManifestEncounteredAddress+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import SargonUniFFI | ||
|
||
extension ManifestEncounteredComponentAddress { | ||
public init(validatingAddress bech32String: String) throws { | ||
self = try newManifestEncounteredComponentAddressFromBech32(string: bech32String) | ||
} | ||
|
||
/// The bech32 encoded string for this address. | ||
public var address: String { | ||
manifestEncounteredComponentAddressToString(address: self) | ||
} | ||
|
||
public var networkID: NetworkId { | ||
manifestEncounteredComponentAddressNetworkId(address: self) | ||
} | ||
|
||
public func formatted(_ format: AddressFormat) -> String { | ||
manifestEncounteredComponentAddressFormatted(address: self, format: format) | ||
} | ||
|
||
|
||
} | ||
|
||
#if DEBUG | ||
extension ManifestEncounteredComponentAddress { | ||
public static func random(networkID: NetworkID) -> Self { | ||
.component(newComponentAddressRandom(networkId: networkID)) | ||
} | ||
|
||
public func mapTo(networkID: NetworkID) -> Self { | ||
manifestEncounteredComponentAddressMapToNetwork(address: self, networkId: networkID) | ||
} | ||
} | ||
#endif // DEBUG |
12 changes: 12 additions & 0 deletions
12
...sions/SampleValues/Profile+Supporting+Types/ManifestEncounteredAddress+SampleValues.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
import SargonUniFFI | ||
|
||
#if DEBUG | ||
extension ManifestEncounteredComponentAddress { | ||
public static let sampleMainnet: Self = newManifestEncounteredComponentAddressSampleMainnet() | ||
public static let sampleMainnetOther: Self = newManifestEncounteredComponentAddressSampleMainnetOther() | ||
|
||
public static let sampleStokenet: Self = newManifestEncounteredComponentAddressSampleStokenet() | ||
public static let sampleStokenetOther: Self = newManifestEncounteredComponentAddressSampleStokenetOther() | ||
} | ||
#endif |
10 changes: 10 additions & 0 deletions
10
.../Sources/Sargon/Extensions/Swiftified/Address/ManifestEncounteredAddress+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import SargonUniFFI | ||
|
||
extension ManifestEncounteredComponentAddress: AddressProtocol { | ||
public var asGeneral: Address { | ||
switch self { | ||
case let .component(componentAddress): Address.component(componentAddress) | ||
case let .locker(lockerAddress): Address.locker(lockerAddress) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
apple/Tests/TestCases/Address/ManifestEncounteredAddressTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import CustomDump | ||
import Foundation | ||
import Sargon | ||
import SargonUniFFI | ||
import XCTest | ||
|
||
final class ManifestEncounteredComponentAddressTests: AddressTest<ManifestEncounteredComponentAddress> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "sargon" | ||
version = "1.1.12" | ||
version = "1.1.13" | ||
edition = "2021" | ||
build = "build.rs" | ||
|
||
|
1 change: 1 addition & 0 deletions
1
crates/sargon/fixtures/transaction/account_locker_claim_fungibles_and_non_fungibles.dat
Large diffs are not rendered by default.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
crates/sargon/fixtures/transaction/account_locker_claim_fungibles_and_non_fungibles.rtm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CALL_METHOD | ||
Address("locker_tdx_2_1drgp40wpu5cj0zady4s0pec6rld8muge0j2xx9xuwwc474uzlgja6a") | ||
"claim" | ||
Address("account_tdx_2_12xlu6x99ssrwrs8cnafka8476ursxfyfde3kfyk7d4s9c5kdvcs77x") | ||
Address("resource_tdx_2_1nflxr7dvp29hxhjjp53strsdgv2kv9dxlx6ys52lafrgyljrhwkt27") | ||
Decimal("4") | ||
; | ||
TAKE_FROM_WORKTOP | ||
Address("resource_tdx_2_1nflxr7dvp29hxhjjp53strsdgv2kv9dxlx6ys52lafrgyljrhwkt27") | ||
Decimal("4") | ||
Bucket("bucket1") | ||
; | ||
CALL_METHOD | ||
Address("account_tdx_2_12xlu6x99ssrwrs8cnafka8476ursxfyfde3kfyk7d4s9c5kdvcs77x") | ||
"deposit" | ||
Bucket("bucket1") | ||
; | ||
CALL_METHOD | ||
Address("locker_tdx_2_1drgp40wpu5cj0zady4s0pec6rld8muge0j2xx9xuwwc474uzlgja6a") | ||
"claim" | ||
Address("account_tdx_2_12xlu6x99ssrwrs8cnafka8476ursxfyfde3kfyk7d4s9c5kdvcs77x") | ||
Address("resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc") | ||
Decimal("30") | ||
; | ||
TAKE_FROM_WORKTOP | ||
Address("resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc") | ||
Decimal("30") | ||
Bucket("bucket2") | ||
; | ||
CALL_METHOD | ||
Address("account_tdx_2_12xlu6x99ssrwrs8cnafka8476ursxfyfde3kfyk7d4s9c5kdvcs77x") | ||
"deposit" | ||
Bucket("bucket2") | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...engine_toolkit/high_level/sargon_specific_types/manifest_encountered_component_address.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use crate::prelude::*; | ||
|
||
address_union!( | ||
/// A tagged union of all the encountered addresses in the manifest. | ||
/// This is to be primarily used for the "using dApps" section of the wallet's tx review screen. | ||
enum ManifestEncounteredComponentAddress: component, locker | ||
); | ||
|
||
macro_rules! impl_try_from_for_manifest_encountered_address { | ||
($($variant:ident => $address_type:ty),*) => { | ||
impl TryFrom<(ScryptoGlobalAddress, NetworkID)> for ManifestEncounteredComponentAddress { | ||
type Error = CommonError; | ||
|
||
fn try_from(value: (ScryptoGlobalAddress, NetworkID)) -> Result<Self> { | ||
let (global_address, network_id) = value; | ||
|
||
$( | ||
if let Ok(address) = <$address_type>::try_from((global_address, network_id)) { | ||
return Ok(ManifestEncounteredComponentAddress::$variant(address)); | ||
} | ||
)* | ||
|
||
Err(CommonError::FailedToCreateAddressFromGlobalAddressAndNetworkID { | ||
global_address_as_hex: global_address.to_hex(), | ||
network_id, | ||
}) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_try_from_for_manifest_encountered_address!( | ||
Component => ComponentAddress, | ||
Locker => LockerAddress | ||
); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[allow(clippy::upper_case_acronyms)] | ||
type SUT = ManifestEncounteredComponentAddress; | ||
|
||
#[test] | ||
fn sample_values_count() { | ||
let mut set = HashSet::<SUT>::new(); | ||
set.extend(SUT::sample_values_all()); | ||
// Duplicates should be removed | ||
set.extend(SUT::sample_values_all()); | ||
|
||
assert_eq!(set.len(), 8); | ||
} | ||
|
||
#[test] | ||
fn try_from_failure() { | ||
let global_address = ScryptoGlobalAddress::new_or_panic( | ||
ResourceAddress::sample_stokenet() | ||
.scrypto() | ||
.into_node_id() | ||
.0, | ||
); | ||
let network_id = NetworkID::Stokenet; | ||
|
||
let result = SUT::try_from((global_address, network_id)); | ||
assert_eq!( | ||
result.unwrap_err(), | ||
CommonError::FailedToCreateAddressFromGlobalAddressAndNetworkID { | ||
global_address_as_hex: global_address.to_hex(), | ||
network_id, | ||
} | ||
); | ||
} | ||
|
||
macro_rules! generate_try_from_tests { | ||
($($variant:ident => $address_type:ty),*) => { | ||
$( | ||
#[test] | ||
fn $variant() { | ||
let global_address = ScryptoGlobalAddress::new_or_panic( | ||
<$address_type>::sample_stokenet().scrypto().into_node_id().0 | ||
); | ||
let network_id = NetworkID::Stokenet; | ||
|
||
let result = SUT::try_from((global_address, network_id)); | ||
assert!(result.is_ok()); | ||
} | ||
)* | ||
}; | ||
} | ||
|
||
generate_try_from_tests!( | ||
component => ComponentAddress, | ||
locker => LockerAddress | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We can try this.
But it is possible this breaks test Swift - and possible it works for most runs but fails for some due to non determinism.
If we have troubles we can change so that Kotlin tests are run AFTER Swift tests:
Which can be done by using
needs: test-Swift