diff --git a/runtime/stdlib/contracts/test.cdc b/runtime/stdlib/contracts/test.cdc index b2e6ba9698..8e7a39da7d 100644 --- a/runtime/stdlib/contracts/test.cdc +++ b/runtime/stdlib/contracts/test.cdc @@ -1,10 +1,10 @@ /// Test contract is the standard library that provides testing functionality in Cadence. /// -pub contract Test { +access(all) contract Test { /// backend emulates a real network. /// - pub let backend: AnyStruct{BlockchainBackend} + access(self) let backend: AnyStruct{BlockchainBackend} init(backend: AnyStruct{BlockchainBackend}) { self.backend = backend @@ -13,7 +13,8 @@ pub contract Test { /// Executes a script and returns the script return value and the status. /// `returnValue` field of the result will be `nil` if the script failed. /// - pub fun executeScript(_ script: String, _ arguments: [AnyStruct]): ScriptResult { + access(all) + fun executeScript(_ script: String, _ arguments: [AnyStruct]): ScriptResult { return self.backend.executeScript(script, arguments) } @@ -21,39 +22,45 @@ pub contract Test { /// The transaction is paid by the service account. /// The returned account can be used to sign and authorize transactions. /// - pub fun createAccount(): Account { + access(all) + fun createAccount(): Account { return self.backend.createAccount() } /// Returns the account for the given address. /// - pub fun getAccount(_ address: Address): Account { + access(all) + fun getAccount(_ address: Address): Account { return self.backend.getAccount(address) } /// Add a transaction to the current block. /// - pub fun addTransaction(_ tx: Transaction) { + access(all) + fun addTransaction(_ tx: Transaction) { self.backend.addTransaction(tx) } /// Executes the next transaction in the block, if any. /// Returns the result of the transaction, or nil if no transaction was scheduled. /// - pub fun executeNextTransaction(): TransactionResult? { + access(all) + fun executeNextTransaction(): TransactionResult? { return self.backend.executeNextTransaction() } /// Commit the current block. /// Committing will fail if there are un-executed transactions in the block. /// - pub fun commitBlock() { + access(all) + fun commitBlock() { self.backend.commitBlock() } /// Executes a given transaction and commit the current block. /// - pub fun executeTransaction(_ tx: Transaction): TransactionResult { + access(all) + fun executeTransaction(_ tx: Transaction): TransactionResult { self.addTransaction(tx) let txResult = self.executeNextTransaction()! self.commitBlock() @@ -62,7 +69,8 @@ pub contract Test { /// Executes a given set of transactions and commit the current block. /// - pub fun executeTransactions(_ transactions: [Transaction]): [TransactionResult] { + access(all) + fun executeTransactions(_ transactions: [Transaction]): [TransactionResult] { for tx in transactions { self.addTransaction(tx) } @@ -79,7 +87,8 @@ pub contract Test { /// Deploys a given contract, and initilizes it with the arguments. /// - pub fun deployContract( + access(all) + fun deployContract( name: String, path: String, arguments: [AnyStruct] @@ -93,40 +102,46 @@ pub contract Test { /// Returns all the logs from the blockchain, up to the calling point. /// - pub fun logs(): [String] { + access(all) + fun logs(): [String] { return self.backend.logs() } /// Returns the service account of the blockchain. Can be used to sign /// transactions with this account. /// - pub fun serviceAccount(): Account { + access(all) + fun serviceAccount(): Account { return self.backend.serviceAccount() } /// Returns all events emitted from the blockchain. /// - pub fun events(): [AnyStruct] { + access(all) + fun events(): [AnyStruct] { return self.backend.events(nil) } /// Returns all events emitted from the blockchain, /// filtered by type. /// - pub fun eventsOfType(_ type: Type): [AnyStruct] { + access(all) + fun eventsOfType(_ type: Type): [AnyStruct] { return self.backend.events(type) } /// Resets the state of the blockchain to the given height. /// - pub fun reset(to height: UInt64) { + access(all) + fun reset(to height: UInt64) { self.backend.reset(to: height) } /// Moves the time of the blockchain by the given delta, /// which should be passed in the form of seconds. /// - pub fun moveTime(by delta: Fix64) { + access(all) + fun moveTime(by delta: Fix64) { self.backend.moveTime(by: delta) } @@ -153,18 +168,19 @@ pub contract Test { } } - pub struct Matcher { + access(all) struct Matcher { - pub let test: ((AnyStruct): Bool) + access(all) let test: ((AnyStruct): Bool) - pub init(test: ((AnyStruct): Bool)) { + init(test: ((AnyStruct): Bool)) { self.test = test } /// Combine this matcher with the given matcher. /// Returns a new matcher that succeeds if this and the given matcher succeed. /// - pub fun and(_ other: Matcher): Matcher { + access(all) + fun and(_ other: Matcher): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return self.test(value) && other.test(value) }) @@ -174,7 +190,8 @@ pub contract Test { /// Returns a new matcher that succeeds if this or the given matcher succeed. /// If this matcher succeeds, then the other matcher would not be tested. /// - pub fun or(_ other: Matcher): Matcher { + access(all) + fun or(_ other: Matcher): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return self.test(value) || other.test(value) }) @@ -183,29 +200,29 @@ pub contract Test { /// ResultStatus indicates status of a transaction or script execution. /// - pub enum ResultStatus: UInt8 { - pub case succeeded - pub case failed + access(all) enum ResultStatus: UInt8 { + access(all) case succeeded + access(all) case failed } /// Result is the interface to be implemented by the various execution /// operations, such as transactions and scripts. /// - pub struct interface Result { + access(all) struct interface Result { /// The result status of an executed operation. /// - pub let status: ResultStatus + access(all) let status: ResultStatus /// The optional error of an executed operation. /// - pub let error: Error? + access(all) let error: Error? } /// The result of a transaction execution. /// - pub struct TransactionResult: Result { - pub let status: ResultStatus - pub let error: Error? + access(all) struct TransactionResult: Result { + access(all) let status: ResultStatus + access(all) let error: Error? init(status: ResultStatus, error: Error?) { self.status = status @@ -215,10 +232,10 @@ pub contract Test { /// The result of a script execution. /// - pub struct ScriptResult: Result { - pub let status: ResultStatus - pub let returnValue: AnyStruct? - pub let error: Error? + access(all) struct ScriptResult: Result { + access(all) let status: ResultStatus + access(all) let returnValue: AnyStruct? + access(all) let error: Error? init(status: ResultStatus, returnValue: AnyStruct?, error: Error?) { self.status = status @@ -229,8 +246,8 @@ pub contract Test { // Error is returned if something has gone wrong. // - pub struct Error { - pub let message: String + access(all) struct Error { + access(all) let message: String init(_ message: String) { self.message = message @@ -239,9 +256,9 @@ pub contract Test { /// Account represents info about the account created on the blockchain. /// - pub struct Account { - pub let address: Address - pub let publicKey: PublicKey + access(all) struct Account { + access(all) let address: Address + access(all) let publicKey: PublicKey init(address: Address, publicKey: PublicKey) { self.address = address @@ -251,11 +268,11 @@ pub contract Test { /// Transaction that can be submitted and executed on the blockchain. /// - pub struct Transaction { - pub let code: String - pub let authorizers: [Address] - pub let signers: [Account] - pub let arguments: [AnyStruct] + access(all) struct Transaction { + access(all) let code: String + access(all) let authorizers: [Address] + access(all) let signers: [Account] + access(all) let arguments: [AnyStruct] init(code: String, authorizers: [Address], signers: [Account], arguments: [AnyStruct]) { self.code = code @@ -267,40 +284,47 @@ pub contract Test { /// BlockchainBackend is the interface to be implemented by the backend providers. /// - pub struct interface BlockchainBackend { + access(all) struct interface BlockchainBackend { /// Executes a script and returns the script return value and the status. /// `returnValue` field of the result will be `nil` if the script failed. /// - pub fun executeScript(_ script: String, _ arguments: [AnyStruct]): ScriptResult + access(all) + fun executeScript(_ script: String, _ arguments: [AnyStruct]): ScriptResult /// Creates a signer account by submitting an account creation transaction. /// The transaction is paid by the service account. /// The returned account can be used to sign and authorize transactions. /// - pub fun createAccount(): Account + access(all) + fun createAccount(): Account /// Returns the account for the given address. /// - pub fun getAccount(_ address: Address): Account + access(all) + fun getAccount(_ address: Address): Account /// Add a transaction to the current block. /// - pub fun addTransaction(_ tx: Transaction) + access(all) + fun addTransaction(_ tx: Transaction) /// Executes the next transaction in the block, if any. /// Returns the result of the transaction, or nil if no transaction was scheduled. /// - pub fun executeNextTransaction(): TransactionResult? + access(all) + fun executeNextTransaction(): TransactionResult? /// Commit the current block. /// Committing will fail if there are un-executed transactions in the block. /// - pub fun commitBlock() + access(all) + fun commitBlock() /// Deploys a given contract, and initilizes it with the arguments. /// - pub fun deployContract( + access(all) + fun deployContract( name: String, path: String, arguments: [AnyStruct] @@ -308,26 +332,31 @@ pub contract Test { /// Returns all the logs from the blockchain, up to the calling point. /// - pub fun logs(): [String] + access(all) + fun logs(): [String] /// Returns the service account of the blockchain. Can be used to sign /// transactions with this account. /// - pub fun serviceAccount(): Account + access(all) + fun serviceAccount(): Account /// Returns all events emitted from the blockchain, optionally filtered /// by type. /// - pub fun events(_ type: Type?): [AnyStruct] + access(all) + fun events(_ type: Type?): [AnyStruct] /// Resets the state of the blockchain to the given height. /// - pub fun reset(to height: UInt64) + access(all) + fun reset(to height: UInt64) /// Moves the time of the blockchain by the given delta, /// which should be passed in the form of seconds. /// - pub fun moveTime(by delta: Fix64) + access(all) + fun moveTime(by delta: Fix64) /// Creates a snapshot of the blockchain, at the /// current ledger state, with the given name. @@ -345,7 +374,8 @@ pub contract Test { /// Returns a new matcher that negates the test of the given matcher. /// - pub fun not(_ matcher: Matcher): Matcher { + access(all) + fun not(_ matcher: Matcher): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return !matcher.test(value) }) @@ -355,7 +385,8 @@ pub contract Test { /// a ScriptResult or TransactionResult and the ResultStatus is succeeded. /// Returns false in any other case. /// - pub fun beSucceeded(): Matcher { + access(all) + fun beSucceeded(): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return (value as! {Result}).status == ResultStatus.succeeded }) @@ -365,7 +396,8 @@ pub contract Test { /// a ScriptResult or TransactionResult and the ResultStatus is failed. /// Returns false in any other case. /// - pub fun beFailed(): Matcher { + access(all) + fun beFailed(): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return (value as! {Result}).status == ResultStatus.failed }) @@ -373,7 +405,8 @@ pub contract Test { /// Returns a new matcher that checks if the given test value is nil. /// - pub fun beNil(): Matcher { + access(all) + fun beNil(): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return value == nil }) @@ -383,7 +416,8 @@ pub contract Test { /// a script or transaction, has failed and contains the given error /// message. /// - pub fun assertError(_ result: {Result}, errorMessage: String) { + access(all) + fun assertError(_ result: {Result}, errorMessage: String) { pre { result.status == ResultStatus.failed: "no error was found" }