Help us shape the future of Go! Take the 2026 Go Developer Survey

tests

package
v2.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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 ContractInterfaceSimple = Resource{
	Name:     "ISimple",
	Filename: "contractInterfaceSimple.cdc",
	Source: []byte(`
		access(all) contract interface ISimple {
			access(all) fun aFunc() 
	}
	`),
}
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 ContractSimpleWithArgsUpdated = Resource{
	Name:     "Simple",
	Filename: "contractArgs.cdc",
	Source: []byte(`
		access(all) contract Simple {
			access(all) let id: UInt64
			access(all) fun newFunc() {}
			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(`
        import Test

        access(all) fun testSimple() {
            Test.assert(true)
        }
	`),
}
View Source
var TestScriptSimpleFailing = Resource{
	Filename: "./testScriptSimpleFailing.cdc",
	Source: []byte(`
        import Test

        access(all) fun testSimple() {
            Test.assert(false)
        }
	`),
}
View Source
var TestScriptWithCoverage = Resource{
	Filename: "testScriptWithCoverage.cdc",
	Source: []byte(`
        import Test
        import "FooContract"


        access(all) fun setup() {
            let err = Test.deployContract(
                name: "FooContract",
                path: "FooContract.cdc",
                arguments: []
            )

            Test.expect(err, Test.beNil())
        }

        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 = FooContract.getIntegerTrait(input)

                // Assert
                Test.assertEqual(testInputs[input]!, result)
            }
        }

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

            // Assert
            Test.assertEqual(FooContract.getIntegerTrait(78557), "Sierpinski")
        }
	`),
}
View Source
var TestScriptWithFileRead = Resource{
	Filename: "testScriptWithFileRead.cdc",
	Source: []byte(`
        import Test

        access(all) fun testSimple() {
            let content = Test.readFile("./someFile.cdc")
            Test.assertEqual("This was read from a file!", content)
        }
	`),
}
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 Test
        import "Hello"

        access(all) fun setup() {
            let err = Test.deployContract(
                name: "Hello",
                path: "contractHello.cdc",
                arguments: []
            )
            Test.expect(err, Test.beNil())
        }

        access(all) fun testSimple() {
            Test.assertEqual("Hello, World!", Hello.greeting)
        }
	`),
}
View Source
var TestScriptWithMissingContract = Resource{
	Filename: "testScriptWithImport.cdc",
	Source: []byte(`
        import Test
        import "ApprovalVoting"

        access(all) fun setup() {
            let err = Test.deployContract(
                name: "ApprovalVoting",
                path: "ApprovalVoting.cdc",
                arguments: []
            )
            Test.expect(err, Test.beNil())
        }
	`),
}
View Source
var TestScriptWithRelativeImports = Resource{
	Filename: "testScriptWithRelativeImport.cdc",
	Source: []byte(`
        import Test
        import FooContract from "../contracts/FooContract.cdc"
        import Hello from "../contracts/contractHello.cdc"

        access(all) fun setup() {
            var err = Test.deployContract(
                name: "FooContract",
                path: "../contracts/FooContract.cdc",
                arguments: []
            )
            Test.expect(err, Test.beNil())

            err = Test.deployContract(
                name: "Hello",
                path: "../contracts/contractHello.cdc",
                arguments: []
            )
            Test.expect(err, Test.beNil())
        }

        access(all) fun testSimple() {
            Test.assertEqual("Enormous", FooContract.getIntegerTrait(100001))
            Test.assertEqual("Hello, World!", Hello.greeting)
        }
	`),
}
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 NewAccountWithContracts

func NewAccountWithContracts(address string, contracts ...Resource) *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