tests

package
v1.5.0-stable-cadence.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2023 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContractA = Resource{
	Name:     "ContractA",
	Filename: "contractA.cdc",
	Source:   []byte(`access(all) contract ContractA {}`),
}
View Source
var ContractAA = Resource{
	Name:     "ContractAA",
	Filename: "contractAA.cdc",
	Source:   []byte(`access(all) contract ContractAA {}`),
}
View Source
var ContractB = Resource{
	Name:     "ContractB",
	Filename: "contractB.cdc",
	Source: []byte(`
		import ContractA from "./contractA.cdc"
		access(all) contract ContractB {}
	`),
}
View Source
var ContractBB = Resource{
	Name:     "ContractBB",
	Filename: "contractBB.cdc",
	Source: []byte(`
		import "ContractAA"
		access(all) contract ContractB {}
	`),
}
View Source
var ContractC = Resource{
	Name:     "ContractC",
	Filename: "contractC.cdc",
	Source: []byte(`
		import ContractB from "./contractB.cdc"
		import ContractA from "./contractA.cdc"

		access(all) contract ContractC {
			access(all) let x: String
			init(x: String) {
				self.x = x
			}
		}
	`),
}
View Source
var ContractCC = Resource{
	Name:     "ContractCC",
	Filename: "contractCC.cdc",
	Source: []byte(`
		import "ContractBB"
		import "ContractAA"

		access(all) contract ContractC {
			access(all) let x: String
			init(x: String) {
				self.x = x
			}
		}
	`),
}
View Source
var ContractEvents = Resource{
	Name:     "ContractEvents",
	Filename: "contractEvents.cdc",
	Source: []byte(`
		access(all) contract ContractEvents {
			access(all) struct S {
				access(all) var x: Int
				access(all) var y: String
				
				init(x: Int, y: String) {
					self.x = x
					self.y = y
				}
			}

			access(all) event EventA(x: Int)
			access(all) event EventB(x: Int, y: Int)
			access(all) event EventC(x: UInt8)
			access(all) event EventD(x: String)
			access(all) event EventE(x: UFix64) 
			access(all) event EventF(x: Address)
			access(all) event EventG(x: [UInt8])
			access(all) event EventH(x: [[UInt8]])
			access(all) event EventI(x: {String: Int})
			access(all) event EventJ(x: S)
			
			init() {
				emit EventA(x: 1)				
				emit EventB(x: 4, y: 2)	
				emit EventC(x: 1)
				emit EventD(x: "hello")
				emit EventE(x: 10.2)
				emit EventF(x: 0x436164656E636521)
				emit EventG(x: "hello".utf8)
				emit EventH(x: ["hello".utf8, "world".utf8])
				emit EventI(x: { "hello": 1337 })
				emit EventJ(x: S(x: 1, y: "hello world"))
			}
		}
	`),
}
View Source
var ContractFooCoverage = Resource{
	Name:     "FooContract",
	Filename: "FooContract.cdc",
	Source: []byte(`
		access(all) contract FooContract {
			access(all) let specialNumbers: {Int: String}

			init() {
				self.specialNumbers = {
					1729: "Harshad",
					8128: "Harmonic",
					41041: "Carmichael"
				}
			}

			access(all) fun addSpecialNumber(_ n: Int, _ trait: String) {
				self.specialNumbers[n] = trait
			}

			access(all) fun getIntegerTrait(_ n: Int): String {
				if n < 0 {
					return "Negative"
				} else if n == 0 {
					return "Zero"
				} else if n < 10 {
					return "Small"
				} else if n < 100 {
					return "Big"
				} else if n < 1000 {
					return "Huge"
				}

				if self.specialNumbers.containsKey(n) {
					return self.specialNumbers[n]!
				}

				return "Enormous"
			}
		}
	`),
}
View Source
var ContractHelloString = Resource{
	Name:     "Hello",
	Filename: "contractHello.cdc",
	Source: []byte(`
		access(all) contract Hello {
			access(all) let greeting: String
			init() {
				self.greeting = "Hello, World!"
			}
			access(all) fun hello(): String {
				return self.greeting
			}
		}
	`),
}
View Source
var ContractSimple = Resource{
	Name:     "Simple",
	Filename: "contractSimple.cdc",
	Source: []byte(`
		access(all) contract Simple {}
	`),
}
View Source
var ContractSimpleUpdated = Resource{
	Name:     "Simple",
	Filename: "contractSimpleUpdated.cdc",
	Source: []byte(`
		access(all) contract Simple {
			access(all) fun newFunc() {}
		}
	`),
}
View Source
var ContractSimpleWithArgs = Resource{
	Name:     "Simple",
	Filename: "contractArgs.cdc",
	Source: []byte(`
		access(all) contract Simple {
			access(all) let id: UInt64
			init(initId: UInt64) {
				self.id = initId
			}
		}
	`),
}
View Source
var HelperImport = Resource{
	Filename: "test_helpers.cdc",
	Source: []byte(`
		access(all) fun double(_ x: Int): Int {
			return x * 2
		}
	`),
}
View Source
var ScriptArgString = Resource{
	Filename: "scriptArg.cdc",
	Source: []byte(`
		access(all) fun main(name: String): String {
		  return "Hello ".concat(name)
		}
	`),
}
View Source
var ScriptImport = Resource{
	Filename: "scriptImport.cdc",
	Source: []byte(`
		import Hello from "./contractHello.cdc"

		access(all) fun main(): String {
		  return "Hello ".concat(Hello.greeting)
		}
	`),
}
View Source
var ScriptWithError = Resource{
	Filename: "scriptError.cdc",
	Source: []byte(`
	    	access(all) fun main(name: String): Strin {
		  return "Hello ".concat(name)
		}
	`),
}
View Source
var SomeFile = Resource{
	Filename: "someFile.cdc",
	Source:   []byte(`This was read from a file!`),
}
View Source
var TestScriptSimple = Resource{
	Filename: "./testScriptSimple.cdc",
	Source: []byte(`
        access(all) fun testSimple() {
            assert(true)
        }
    `),
}
View Source
var TestScriptSimpleFailing = Resource{
	Filename: "./testScriptSimpleFailing.cdc",
	Source: []byte(`
        access(all) fun testSimple() {
            assert(false)
        }
    `),
}
View Source
var TestScriptWithCoverage = Resource{
	Filename: "testScriptWithCoverage.cdc",
	Source: []byte(`
		import Test
		import "FooContract"

		access(all) let foo = FooContract()

		access(all) fun testGetIntegerTrait() {
			// Arrange
			let testInputs: {Int: String} = {
				-1: "Negative",
				0: "Zero",
				9: "Small",
				99: "Big",
				999: "Huge",
				1001: "Enormous",
				1729: "Harshad",
				8128: "Harmonic",
				41041: "Carmichael"
			}

			for input in testInputs.keys {
				// Act
				let result = foo.getIntegerTrait(input)

				// Assert
				Test.assert(result == testInputs[input])
			}
		}

		access(all) fun testAddSpecialNumber() {
			// Act
			foo.addSpecialNumber(78557, "Sierpinski")

			// Assert
			Test.assert("Sierpinski" == foo.getIntegerTrait(78557))
		}

		access(all) fun testExecuteScript() {
			// Arrange
			let blockchain = Test.newEmulatorBlockchain()

			// Act
			let code = "access(all) fun main(): Int { return 42 }"
			let result = blockchain.executeScript(code, [])
			let answer = (result.returnValue as! Int?)!

			// Assert
			Test.assert(answer == 42)
		}
    `),
}
View Source
var TestScriptWithFileRead = Resource{
	Filename: "testScriptWithFileRead.cdc",
	Source: []byte(`
        import Test

        access(all) fun testSimple() {
            let content = Test.readFile("./someFile.cdc")
            assert(content == "This was read from a file!")
        }
    `),
}
View Source
var TestScriptWithHelperImport = Resource{
	Filename: "testScriptWithHelperImport.cdc",
	Source: []byte(`
		import Test
		import "test_helpers.cdc"

		access(all) fun testDouble() {
			Test.expect(double(2), Test.equal(4))
		}
	`),
}
View Source
var TestScriptWithImport = Resource{
	Filename: "testScriptWithImport.cdc",
	Source: []byte(`
        import "Hello"

        access(all) fun testSimple() {
            let hello = Hello()
            assert(hello.greeting == "Hello, World!")
        }
    `),
}
View Source
var TestScriptWithRelativeImports = Resource{
	Filename: "testScriptWithRelativeImport.cdc",
	Source: []byte(`
        import "FooContract"
        import "Hello"

        access(all) fun testSimple() {
            let hello = Hello()
            assert(hello.greeting == "Hello, World!")

            let fooContract = FooContract()
            assert("Carmichael" == fooContract.getIntegerTrait(41041))
        }
    `),
}
View Source
var TransactionArgString = Resource{
	Filename: "transactionArg.cdc",
	Source: []byte(`
		transaction(greeting: String) {
			let guest: Address
			
			prepare(authorizer: &Account) {
				self.guest = authorizer.address
			}
			
			execute {
				log(greeting.concat(",").concat(self.guest.toString()))
			}
		}
	`),
}
View Source
var TransactionImports = Resource{
	Filename: "transactionImport.cdc",
	Source: []byte(`
		import Hello from "./contractHello.cdc"
		
		transaction() {
			prepare(authorizer: &Account) {}
			execute {
				Hello.hello()
			}
		}
	`),
}
View Source
var TransactionMultipleDeclarations = Resource{
	Filename: "transactionMultipleDec.cdc",
	Source: []byte(`
		access(all) fun dummy(_ address: Address): Void {}

		transaction() {
			prepare(authorizer: &Account) {}
		}
	`),
}
View Source
var TransactionSimple = Resource{
	Filename: "transactionSimple.cdc",
	Source: []byte(`
		transaction() { }
	`),
}
View Source
var TransactionSingleAuth = Resource{
	Filename: "transactionAuth1.cdc",
	Source: []byte(`
		transaction() {
			prepare(authorizer: &Account) {}
		}
	`),
}
View Source
var TransactionTwoAuth = Resource{
	Filename: "transactionAuth2.cdc",
	Source: []byte(`
		transaction() {
			prepare(auth1: &Account, auth2: &Account) {}
		}
	`),
}

Functions

func HashAlgos

func HashAlgos() []crypto.HashAlgorithm

func NewAccountCreateResult

func NewAccountCreateResult(address flow.Address) *flow.TransactionResult

func NewAccountWithAddress

func NewAccountWithAddress(address string) *flow.Account

func NewBlock

func NewBlock() *flow.Block

func NewCollection

func NewCollection() *flow.Collection

func NewEvent

func NewEvent(index int, eventId string, fields []cadence.Field, values []cadence.Value) *flow.Event

func NewTransaction

func NewTransaction() *flow.Transaction

func NewTransactionResult

func NewTransactionResult(events []flow.Event) *flow.TransactionResult

func PrivKeys

func PrivKeys() []crypto.PrivateKey

func PubKeys

func PubKeys() []crypto.PublicKey

func ReaderWriter

func ReaderWriter() (afero.Afero, afero.Fs)

func SigAlgos

func SigAlgos() []crypto.SignatureAlgorithm

Types

type Resource

type Resource struct {
	Name     string
	Filename string
	Source   []byte
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL