Skip to content
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

FactorInstanceProvider ("FIP") with Serializable FactorInstancesCache + consumers of "FIP" #254

Merged
merged 150 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 128 commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
3bebfa8
REVERT ME: visibility pub(crate) -> pub
Sajjon Nov 1, 2024
de883ea
PICK ME: Add FactorInstancesProvider::agnostic_paths module
Sajjon Nov 1, 2024
5fccefe
wip factor_instances_provider integration
Sajjon Nov 4, 2024
fa5e3c4
[no ci] wip
CyonAlexRDX Nov 4, 2024
f89ca88
wip
CyonAlexRDX Nov 4, 2024
15067b5
[no ci] wip
CyonAlexRDX Nov 4, 2024
fd8efcc
wip
CyonAlexRDX Nov 4, 2024
a6afa60
wip
Sajjon Nov 5, 2024
f28330b
wip
CyonAlexRDX Nov 5, 2024
a1f7f46
wip
CyonAlexRDX Nov 5, 2024
791a01a
WIP
Sajjon Nov 5, 2024
130b016
fix tests
CyonAlexRDX Nov 5, 2024
b11415f
fix petition_for_entity tests
Sajjon Nov 5, 2024
d5442e0
fix tests in petition_for_transaction
Sajjon Nov 5, 2024
aeee3f9
fixes
Sajjon Nov 5, 2024
c8b6917
fix tests
CyonAlexRDX Nov 5, 2024
8345c51
fixes
CyonAlexRDX Nov 5, 2024
671e5bf
fixes
CyonAlexRDX Nov 5, 2024
609be2f
wip
CyonAlexRDX Nov 5, 2024
305810b
[no ci] WIP
Sajjon Nov 5, 2024
7606d60
adding keys_collector
CyonAlexRDX Nov 5, 2024
4a325de
WIP migrating over the FactorInstancesProvider
CyonAlexRDX Nov 5, 2024
c5ee20c
wip integrating FactorInstancesProvider
CyonAlexRDX Nov 5, 2024
f1cd228
[no ci] WIP
Sajjon Nov 6, 2024
e1df91e
[no ci] wip
CyonAlexRDX Nov 6, 2024
8a7a094
[no ci] wip
CyonAlexRDX Nov 6, 2024
fd6b1d2
[no ci] wip
CyonAlexRDX Nov 6, 2024
cf976e0
[no ci] wip
CyonAlexRDX Nov 6, 2024
8f773dc
[no ci] Make FactorInstanceCache use RwLock so we can skip mut
CyonAlexRDX Nov 6, 2024
13207f8
[no ci] wip save load cache
CyonAlexRDX Nov 6, 2024
339a4c6
WIP cache serde
Sajjon Nov 6, 2024
f8e2ea5
[no ci] wip FactorSourceIDFromHashDenseKey
CyonAlexRDX Nov 7, 2024
c62cf91
[no ci] WIP
Sajjon Nov 7, 2024
43f30f7
[no ci] WIP cache client
CyonAlexRDX Nov 7, 2024
1451996
wip FactorInstanceCache
CyonAlexRDX Nov 7, 2024
5543a5a
[no ci] cache client
CyonAlexRDX Nov 7, 2024
e2a7973
[no ci] Only FileSystem FactorInstancesCacheClient removing possibili…
CyonAlexRDX Nov 7, 2024
7fbbac2
[no ci] add test for insert_all
CyonAlexRDX Nov 7, 2024
cf2badb
[no ci] Migrate SOME tests of `FactorInstancesProvider` to use `Facto…
CyonAlexRDX Nov 7, 2024
36e8abe
[no ci] wip sargonos
CyonAlexRDX Nov 7, 2024
a585553
[no ci] WIP
Sajjon Nov 7, 2024
70e5b2f
SargonOS create account with specified FS using FIP
Sajjon Nov 7, 2024
dd7a767
[no ci] WIP
Sajjon Nov 8, 2024
72db84b
[no ci] WIP
Sajjon Nov 8, 2024
8788c7b
[no ci] WIP
Sajjon Nov 8, 2024
51e833b
[no ci] working test KeysDerivationInteractor
CyonAlexRDX Nov 8, 2024
52b406a
wip FIP unit tests
CyonAlexRDX Nov 8, 2024
9d0ce71
[no ci] create_accounts_when_last_is_used_cache_is_fill_only_with_acc…
CyonAlexRDX Nov 8, 2024
0cedb02
[no ci] migrate two more unit tests
CyonAlexRDX Nov 8, 2024
ccca476
[no ci] personas
CyonAlexRDX Nov 8, 2024
001b267
[no ci] wip
CyonAlexRDX Nov 9, 2024
708f9c4
Add `InstancesConsumer` handle - making it possible to defer deletion…
Sajjon Nov 10, 2024
72f7d48
[no ci] WIP
Sajjon Nov 11, 2024
e627f60
wip securify
CyonAlexRDX Nov 11, 2024
d53df46
wip securify
CyonAlexRDX Nov 11, 2024
6ebb7ba
[no ci] WIP
Sajjon Nov 11, 2024
f608c89
[no ci] WIP
Sajjon Nov 11, 2024
741d575
[no ci] wip
CyonAlexRDX Nov 11, 2024
d83c57a
[no ci] working working?
CyonAlexRDX Nov 11, 2024
d705ce6
[no ci] working cache_is_unchanged test
CyonAlexRDX Nov 11, 2024
7276c75
[no ci] add_account_and_personas_mixed
CyonAlexRDX Nov 11, 2024
03db9e4
[no ci] WIP
Sajjon Nov 12, 2024
1202f4e
migrate test_securified_accounts
Sajjon Nov 12, 2024
1e6a801
[no ci] securify_accounts_when_cache_is_half_full_single_factor_sourc…
Sajjon Nov 12, 2024
45b9cb4
[no ci] WIP
Sajjon Nov 12, 2024
b1bf01a
[no ci] migrate securify_personas_when_cache_is_half_full_single_fact…
Sajjon Nov 12, 2024
dafe36f
[no ci] WIP
Sajjon Nov 12, 2024
5c85341
[no ci] WIP
Sajjon Nov 12, 2024
74732bc
[no ci] WIP
Sajjon Nov 12, 2024
936d3a6
[no ci] WIP
Sajjon Nov 12, 2024
8867412
Finished migrating all FactorInstancesProvider unit tests from Sargon…
CyonAlexRDX Nov 12, 2024
abcea55
[no ci] cleanup
CyonAlexRDX Nov 12, 2024
9b990c5
Merge main
CyonAlexRDX Nov 12, 2024
88d4589
make clippy happy
CyonAlexRDX Nov 12, 2024
321849b
revert commit `3bebfa87740a01974ee32c23abc255c0a17b3dc2` which change…
CyonAlexRDX Nov 12, 2024
96a0918
clippy
CyonAlexRDX Nov 12, 2024
560ad3b
bump version
CyonAlexRDX Nov 12, 2024
e3c85fb
rename InstancesConsumer
CyonAlexRDX Nov 12, 2024
939d8a0
gate make_security_structure_of_factor_instances_for_entities_without…
CyonAlexRDX Nov 12, 2024
d6198bb
try make tarpaulin happy
Sajjon Nov 13, 2024
24b4716
remove unused functions
Sajjon Nov 13, 2024
fbfade2
logging off for unit test
Sajjon Nov 13, 2024
440a642
more tests
Sajjon Nov 13, 2024
3feb4ce
use SUT acronym
Sajjon Nov 13, 2024
3367b95
fix Sut -> SUT
Sajjon Nov 13, 2024
0c92a72
split files
Sajjon Nov 13, 2024
0c43c16
Tarpaulin ignore uniffi and macros crate
Sajjon Nov 13, 2024
57d4dab
split out FactorInstancesCacheSnapshot
CyonAlexRDX Nov 13, 2024
faa2c7c
[no ci] cleanup
CyonAlexRDX Nov 13, 2024
3ae41cf
doc interactors
CyonAlexRDX Nov 13, 2024
baf6273
cleanup
CyonAlexRDX Nov 13, 2024
2c723d5
cleanup
CyonAlexRDX Nov 13, 2024
e1c38b3
split files
CyonAlexRDX Nov 13, 2024
6385a9f
more tests
CyonAlexRDX Nov 13, 2024
a755bcc
clean up
CyonAlexRDX Nov 13, 2024
48595eb
split
CyonAlexRDX Nov 13, 2024
e30f94b
more tests
CyonAlexRDX Nov 13, 2024
feb4572
more tests
CyonAlexRDX Nov 13, 2024
47dc2dc
more tests
CyonAlexRDX Nov 13, 2024
ccda42c
[no ci] wip
CyonAlexRDX Nov 14, 2024
c4ed1ac
fix test
Sajjon Nov 14, 2024
9c3dd41
more tests
Sajjon Nov 14, 2024
d480a23
reintroduce transpose cache tests
Sajjon Nov 14, 2024
fac5caf
[no ci] format, bump
CyonAlexRDX Nov 14, 2024
2b0fd69
merge main
CyonAlexRDX Nov 14, 2024
bb52b28
cleanup
CyonAlexRDX Nov 14, 2024
b571170
JSON camelcased for RoleKind with tests
Sajjon Nov 14, 2024
7c4eada
Add `NoUIInteractorForKeyDerivation`
CyonAlexRDX Nov 14, 2024
f1c78bd
noui interactor
CyonAlexRDX Nov 14, 2024
44aa8f9
[no ci] wip
CyonAlexRDX Nov 15, 2024
0e7e70c
[no ci] WIP
Sajjon Nov 15, 2024
623dcde
Merge branch 'main' into integrate_keys_collector
CyonAlexRDX Nov 15, 2024
c57df6e
bump to 1.1.52
CyonAlexRDX Nov 15, 2024
35c9fa6
new driver
CyonAlexRDX Nov 15, 2024
e5d30db
add writable_app_dir_path to FileSystem driver/client
CyonAlexRDX Nov 15, 2024
61adff2
fix swift test
CyonAlexRDX Nov 15, 2024
583c9b1
add missing import in Kotlin
CyonAlexRDX Nov 15, 2024
7b51f18
[no ci] wip
CyonAlexRDX Nov 16, 2024
8d8b454
fix kotlin tests
Sajjon Nov 16, 2024
0ede48e
format
Sajjon Nov 16, 2024
09369d4
wip generlize persona and account operations
Sajjon Nov 16, 2024
67e2909
fix swift
CyonAlexRDX Nov 16, 2024
53e1663
fmt
Sajjon Nov 16, 2024
58715f6
wip unify modify entities
Sajjon Nov 17, 2024
1f8d22b
assert factors unique for some operations
Sajjon Nov 17, 2024
35a3d86
fmt
Sajjon Nov 18, 2024
044f6d1
factor instances assertion tests
Sajjon Nov 18, 2024
35165cf
fix tests
CyonAlexRDX Nov 18, 2024
711eedd
coverage
CyonAlexRDX Nov 18, 2024
e4e8da8
moaar tests
CyonAlexRDX Nov 18, 2024
035ee8c
merge main | fix conflicts (CommonError, SargonOS + accounts)
CyonAlexRDX Nov 18, 2024
aa8f75b
update version
CyonAlexRDX Nov 18, 2024
3152a65
fix clippy by introducing DetailedManifestClassKind
CyonAlexRDX Nov 18, 2024
9cfbd2b
fix swift filesystem driver
Sajjon Nov 18, 2024
337bba7
more tests
Sajjon Nov 19, 2024
ad830a6
polish
CyonAlexRDX Nov 19, 2024
8dfbbae
fix swift filesystem driver
CyonAlexRDX Nov 19, 2024
324a557
merge main | bump to 55 | clippy fix
CyonAlexRDX Nov 19, 2024
5e7e1ec
merge main | bump to 55 | clippy fix
CyonAlexRDX Nov 19, 2024
7fac1be
fix workflows
CyonAlexRDX Nov 19, 2024
3bc824d
test all roles
Sajjon Nov 20, 2024
45a50ea
merge main | clippy fix | bump to 57
CyonAlexRDX Nov 20, 2024
5e9297e
fixes
Sajjon Nov 21, 2024
295513c
PR review comment fixes
Sajjon Nov 21, 2024
3ba7f6c
more review fixes
Sajjon Nov 21, 2024
496437a
clippy fix
Sajjon Nov 21, 2024
986b0b4
remove pub __hidden
Sajjon Nov 21, 2024
3c18549
unneeded import
Sajjon Nov 21, 2024
7e2f483
merge main | bump | add doc
CyonAlexRDX Nov 21, 2024
aebcb04
fix typo
CyonAlexRDX Nov 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .tarpaulin.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[all]
exclude-files = [
# Skip Uniffi crate, we rely on `crates/sargon` AND hosts being tested
"crates/sargon-uniffi/*",
# Skip Uniffi crate, we rely on hosts being tested
"crates/sargon-uniffi-conversion-macros/*",

"crates/sargon/src/lib.rs",
# Too many false negatives (macro usage)
"crates/sargon/src/profile/v100/address/non_fungible_resource_address.rs",
Expand Down
55 changes: 53 additions & 2 deletions Cargo.lock

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
Expand Up @@ -44,27 +44,60 @@
_ io: @Sendable (URL) throws -> T
) throws -> T {
let url = URL(file: path)
guard url.startAccessingSecurityScopedResource() else {
throw CommonError.NotPermissionToAccessFile(path: path)
}
defer { url.stopAccessingSecurityScopedResource() }
#if os(macOS)
guard url.startAccessingSecurityScopedResource() else {
throw CommonError.NotPermissionToAccessFile(path: path)

Check warning on line 49 in apple/Sources/Sargon/Drivers/FileSystem/FileSystemDriver+Data+ContentsOf+URL.swift

View check run for this annotation

Codecov / codecov/patch

apple/Sources/Sargon/Drivers/FileSystem/FileSystemDriver+Data+ContentsOf+URL.swift#L49

Added line #L49 was not covered by tests
}
defer { url.stopAccessingSecurityScopedResource() }
#endif
return try io(url)
}
}

extension FileSystem: FileSystemDriver {

public func writableAppDirPath() async throws -> String {
#if os(iOS)
try fileManager.url(
for: .cachesDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true
).absoluteString
#elseif os(macOS)
URL.temporaryDirectory.path()
#else
fatalError("Unsupported OS")
#endif
}

public func loadFromFile(path: String) async throws -> BagOfBytes? {
try with(path: path) {
try Data(contentsOf: $0)
return try with(path: path) {
let fileExists = fileManager.fileExists(atPath: $0.path())
do {
return try Data(contentsOf: $0)
} catch {
if fileExists {
throw error

Check warning on line 80 in apple/Sources/Sargon/Drivers/FileSystem/FileSystemDriver+Data+ContentsOf+URL.swift

View check run for this annotation

Codecov / codecov/patch

apple/Sources/Sargon/Drivers/FileSystem/FileSystemDriver+Data+ContentsOf+URL.swift#L80

Added line #L80 was not covered by tests
} else {
return nil
}
}
}
}

public func saveToFile(path: String, data: BagOfBytes) async throws {
try with(path: path) {
try data.write(to: $0)
}
}
public func saveToFile(path: String, data: BagOfBytes, isAllowedToOverwrite: Bool) async throws {

try with(path: path) {
if fileManager.fileExists(atPath: $0.path()) {
if !isAllowedToOverwrite {
throw CommonError.FileAlreadyExists(path: path)
}
} else {
fileManager.createFile(atPath: $0.path(), contents: nil)
}
try data.write(to: $0)
}
}

public func deleteFile(path: String) async throws {
try with(path: path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EventBusDriverTests: DriverTest<EventBus> {

let bios = BIOS(drivers: .withEventBus(sut))
let os = await TestOS(bios: bios)
try await os.os.newWallet()
try await os.os.newWallet(shouldPrederiveInstances: false)

try await os.createAccount()
let notifications = await task.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,27 @@ class FileSystemDriverTests: DriverTest<FileSystem> {
let data = Data("This file is completely safe to delete. It was generated by a unit test.".utf8)

let sut = SUT()
try await sut.saveToFile(path: path, data: data)
try await sut.saveToFile(path: path, data: data, isAllowedToOverwrite: true)
let loaded = try await sut.loadFromFile(path: path)
XCTAssertEqual(loaded, data)

XCTAssertTrue(FileManager.default.fileExists(atPath: path))
try await sut.deleteFile(path: path)
XCTAssertFalse(FileManager.default.fileExists(atPath: path))
}

func test_without_overwrite() async throws {
let nameOfFile = "delete_me_\(UUID().uuidString).txt"
let path = URL.temporaryDirectory.appending(path: nameOfFile, directoryHint: .notDirectory).path()
let data = Data("This file is completely safe to delete. It was generated by a unit test.".utf8)

let sut = SUT()
try await sut.saveToFile(path: path, data: data, isAllowedToOverwrite: true)
do {
try await sut.saveToFile(path: path, data: data, isAllowedToOverwrite: false)
XCTFail("Expected throw")
} catch {
// Good, expected to throw
}
}
}
22 changes: 11 additions & 11 deletions apple/Tests/IntegrationTests/SargonOS/TestOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class TestOSTests: OSTest {
let bus = EventBus()
let drivers = Drivers.withEventBus(bus)
let sut = await TestOS(bios: .init(drivers: drivers))
try await sut.os.newWallet()
try await sut.os.newWallet(shouldPrederiveInstances: false)
let n = 3

let task = Task {
Expand All @@ -59,17 +59,17 @@ final class TestOSTests: OSTest {
}

func test_create_account_returned() async throws {
let sut = await TestOS()
try await sut.os.newWallet()
let sut = await TestOS()
try await sut.os.newWallet(shouldPrederiveInstances: false)
let displayName: DisplayName = "New"
let account = try await sut.createAccount(named: displayName)
XCTAssertEqual(account.displayName, displayName)
XCTAssertEqual(try sut.accountsForDisplayOnCurrentNetwork, [AccountForDisplay(account)])
}

func test_create_account_returned_can_be_looked_up() async throws {
let sut = await TestOS()
try await sut.os.newWallet()
let sut = await TestOS.init()
try await sut.os.newWallet(shouldPrederiveInstances: false)
let displayName: DisplayName = "New"
let account = try await sut.createAccount(named: displayName)
let lookedUp = try sut.accountByAddress(account.address)
Expand All @@ -78,20 +78,20 @@ final class TestOSTests: OSTest {

func test_lookup_throws_for_unknown_accounts() async throws {
let sut = await TestOS()
try await sut.os.newWallet()
try await sut.os.newWallet(shouldPrederiveInstances: false)
XCTAssertThrowsError(try sut.accountByAddress(.sample))
}

func test_new_profile_has_preset_gateways() async throws {
let sut = await TestOS()
try await sut.os.newWallet()
try await sut.os.newWallet(shouldPrederiveInstances: false)
let gateways = try sut.gateways
XCTAssertEqual(gateways, .preset)
}

func test_if_replace_profile_throws() async throws {
let sut = await TestOS()
try await sut.os.newWallet()
try await sut.os.newWallet(shouldPrederiveInstances: false)
var profile = try sut.os.profile()
profile.header.id = ProfileID() // mutate profile
do {
Expand All @@ -104,19 +104,19 @@ final class TestOSTests: OSTest {

func test_we_can_mutate_profile_in_swift_and_save_then_profile_is_updated() async throws {
let sut = await TestOS()
try await sut.os.newWallet()
try await sut.os.newWallet(shouldPrederiveInstances: false)
var profile = try sut.os.profile()
let creatingDevice = profile.header.creatingDevice
let newCreatingDevice = DeviceInfo.sampleOther
XCTAssertNotEqual(newCreatingDevice, creatingDevice)
profile.header.creatingDevice = newCreatingDevice // mutate profile
profile.header.creatingDevice = newCreatingDevice // mutate profile
try await sut.os.setProfile(profile: profile)
XCTAssertEqual(try sut.os.profile().header.creatingDevice, newCreatingDevice) // assert change worked
}

func test_batch_create_many_accounts() async throws {
let sut = await TestOS()
try await sut.os.newWallet()
try await sut.os.newWallet(shouldPrederiveInstances: false)
let n: UInt16 = 4
try await sut.batchCreateAccounts(count: n, namePrefix: "Unnamed")
XCTAssertEqual(try sut.accountsOnCurrentNetwork.map(\.displayName.value), (0..<n).map { "Unnamed \($0)" })
Expand Down
4 changes: 2 additions & 2 deletions crates/sargon-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sargon-uniffi"
# Don't forget to update version in crates/sargon/Cargo.toml
version = "1.1.51"
version = "1.1.52"
edition = "2021"
build = "build.rs"

Expand All @@ -19,7 +19,7 @@ required-features = ["build-binary"]
[dependencies]

sargon = { path = "../sargon" }
sargon-uniffi-conversion-macros = { path = "../sargon-uniffi-conversion-macros" }
sargon-uniffi-conversion-macros = { path = "../sargon-uniffi-conversion-macros" }

radix-engine-toolkit = { git = "https://github.com/radixdlt/radix-engine-toolkit", rev = "263bc81f497f686b7327ffcc45fbaad6e04df85a" }

Expand Down
Loading
Loading