tests

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

		pub contract ContractC {
			pub 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"

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

			pub event EventA(x: Int)
			pub event EventB(x: Int, y: Int)
			pub event EventC(x: UInt8)
			pub event EventD(x: String)
			pub event EventE(x: UFix64) 
			pub event EventF(x: Address)
			pub event EventG(x: [UInt8])
			pub event EventH(x: [[UInt8]])
			pub event EventI(x: {String: Int})
			pub 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(`
		pub contract FooContract {
			pub let specialNumbers: {Int: String}

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

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

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

		pub fun main(): String {
		  return "Hello ".concat(Hello.greeting)
		}
	`),
}
View Source
var ScriptWithError = Resource{
	Filename: "scriptError.cdc",
	Source: []byte(`
	    	pub 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

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

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

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

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

        pub 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)
            }
        }

        pub 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

        pub 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"

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

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

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

        pub 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"

        pub 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())
        }

        pub 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: AuthAccount) {
				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: AuthAccount) {}
			execute {
				Hello.hello()
			}
		}
	`),
}
View Source
var TransactionMultipleDeclarations = Resource{
	Filename: "transactionMultipleDec.cdc",
	Source: []byte(`
		pub fun dummy(_ address: Address): Void {}

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

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