Cotton code
23 lines · 1.2 KB · SwiftRaw
import XCTest@testable import CottonKitfinal class PersonalSignerTests: XCTestCase {    // A paired phone publishes before the keeper has wrapped its key. Create    // must finish that sync handoff before retrying the signed mutation.    func testCreateWaitsForTheWrapBeforeRetryingTheMutation() async throws {        let core = ScriptedCore([            "databases.create": .refuse(code: "vault_locked", message: "Unlock Personal"),            "vault.publishKey": .ok("{}"),            "vault.unlock": .refuse(code: "vault_not_wrapped_yet", message: "Waiting for the Mac"),            "sync.now": .ok("{}")        ])        let source = CoreDatabases(core: core, publicKey: { "synthetic-public" }, privateKey: { "synthetic-private" }, pause: {            await core.answer("vault.unlock", .ok("{}"))            await core.answer("databases.create", .ok(#"{"id":"garden","name":"Garden"}"#))        })        let made = try await source.create(name: "Garden", toolkit: DatabaseToolkit.all[0])        XCTAssertEqual(made.databaseId, "garden")        let methods = await core.methodsCalled()        XCTAssertEqual(methods, ["databases.create", "vault.publishKey", "vault.unlock", "sync.now", "vault.unlock", "databases.create"])    }}