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

tests

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

Testing

Mocks

Mocks are generated using mockery.

To regenerate gateway mock go to the gateway directory /pkg/flowkit/gateway and run the command:

mockery --name=Gateway --output ../../../tests/mocks 

Documentation

Index

Constants

View Source
const (
	GetAccountFunc            = "GetAccount"
	SendSignedTransactionFunc = "SendSignedTransaction"
	GetCollectionFunc         = "GetCollection"
	GetTransactionResultFunc  = "GetTransactionResult"
	GetEventsFunc             = "GetEvents"
	GetLatestBlockFunc        = "GetLatestBlock"
	GetBlockByHeightFunc      = "GetBlockByHeight"
	GetBlockByIDFunc          = "GetBlockByID"
	ExecuteScriptFunc         = "ExecuteScript"
	GetTransactionFunc        = "GetTransaction"
)

Variables

View Source
var ContractA = resource{
	Name:     "ContractA",
	Filename: "contractA.cdc",
	Source:   []byte(`pub contract ContractA {}`),
}
View Source
var ContractB = resource{
	Name:     "ContractB",
	Filename: "contractB.cdc",
	Source: []byte(`
		import ContractA from "./contractA.cdc"
		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 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 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 let greeting: String
			init() {
				self.greeting = "Foo"
			}
		}
	`),
}
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 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 TransactionSimple = resource{
	Filename: "transactionSimple.cdc",
	Source: []byte(`
		transaction() {}
	`),
}

Functions

func Alice added in v0.24.0

func Alice() *flowkit.Account

func Bob added in v0.24.0

func Bob() *flowkit.Account

func Charlie added in v0.24.0

func Charlie() *flowkit.Account

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 added in v0.24.0

func PrivKeys() []crypto.PrivateKey

func PubKeys added in v0.24.0

func PubKeys() []crypto.PublicKey

func ReaderWriter added in v0.24.0

func ReaderWriter() afero.Afero

Types

type TestGateway added in v0.24.0

type TestGateway struct {
	Mock                  *mocks.Gateway
	SendSignedTransaction *mock.Call
	GetAccount            *mock.Call
	GetCollection         *mock.Call
	GetTransactionResult  *mock.Call
	GetEvents             *mock.Call
	GetLatestBlock        *mock.Call
	GetBlockByHeight      *mock.Call
	GetBlockByID          *mock.Call
	ExecuteScript         *mock.Call
	GetTransaction        *mock.Call
}

func DefaultMockGateway added in v0.24.0

func DefaultMockGateway() *TestGateway

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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