Categorygithub.com/bjartek/overflow/v2
modulepackage
2.0.1
Repository: https://github.com/bjartek/overflow.git
Documentation: pkg.go.dev

# README

Coverage Status ci

Overflow

This is the v2 version of overflow to be used with cadence 1.0, for the v1 version that targets 0.x look in the v1 branch.

A DSL written in golang to be used in tests or to run a story of interactions against either an local emulator, testnet, mainnet or an in memory instance of the flow-emulator.

Use case scenarios include:

  • demo purposes
  • integration testing of combinations of scripts/transactions
  • batch jobs.

For a standalone example on how overflow can be used look at https://github.com/bjartek/flow-nft-overflow it has both an interactive demo and unit tests for an example NFT contract.

Main features

  • Uses a shared golang builder pattern for almost all interactions.
  • Well documented source code
  • supports all variants of multi-sign, Two authorizers, proposer and payer can be different.
  • when refering to an account/address you can use the logical name for that stakeholder defined in flow json. the same stakeholder IE admin can have different addresses on each network
  • can be run in embedded in memory mode that will start emulator, deploy contracts, create stakeholders and run interactions (scripts/transactions) against this embedded system and then stop it when it ends.
  • has a DSL to fetch Events and optionally store progress in a file. This can be chained into indexers/crawlers/notification services.
  • all interactions can be specified inline as well as from files
  • transform all interactions into a NPM module that can be published for the frontend to use. this json file that is generate has the option to filter out certain interactions and to strip away network suffixes if you have multiple local interactions that should map to the same logical name in the client for each network
  • the interaction (script/tx) dsl has a rich set of assertions
  • arguments to interactions are all named that is the same name in that is in the argument must be used with the Arg("name", "value") builder. The value in this example can be either a primitive go value or a cadence.Value.
  • supports shared instance in test to collect coverage report and rollback after/before each test. See example folder.

Gotchas

  • When specifying extra accounts that are created on emulator they are created in alphabetical order, the addresses the emulator assign is always fixed.
  • tldr; Name your stakeholder accounts in alphabetical order, we suggest admin, bob, charlie, demi, eddie
  • When writing integration tests, tests must be in the same folder as flow.json with contracts and transactions/scripts in subdirectories in order for the path resolver to work correctly

Resources

Usage

First create a project directory, initialize the go module and install overflow:

mkdir test-overflow && cd test-overflow
flow init
go mod init example.com/test-overflow
go get github.com/bjartek/overflow/v2

Then create a task file:

touch tasks/main.go

In that task file, you can then import overflow and use it to your convenience, for example:

package main

import (
    "fmt"

    //if you imports this with .  you do not have to repeat overflow everywhere 
    . "github.com/bjartek/overflow/v2"
)

func main() {

	//start an in memory emulator by default
  // there are two interfaces published for Overflow, `OverflowClient` and `OverrflowBetaClient` that has unstable api, I urge you to store this as the client and not the impl. Currenly the Overflow method returns the impl so you can choose.
	o := Overflow()
	
	//the Tx DSL runs an transaction
	o.Tx("name_of_transaction", SignProposeAndPayAs("bob"), Arg("name", "bob")).Print()
	
	//Run a script/get interaction against the same in memory chain
	o.Script("name_of_script", Arg("name", "bob")).Print()
}

Then you can run

go run ./tasks/main.go

This is a minimal example that run a transction and a script, but from there you can branch out.

The following env vars are supported

  • OVERFLOW_ENV : set the environment to run against "emulator|embedded|testnet|mainnet|testing" (embedded is standard)
  • OVEFFLOW_CONTINUE: if you do not want overflow to deploy contracts and accounts on emulator you can set this to true
  • OVERFLOW_LOGGING: Set this to 0-4 to get increasing log

Usage flix


import (
	. "github.com/bjartek/overflow/v2"
)

func main() {
	o := Overflow(WithNetwork("mainnet"))

	o.FlixTx("transfer-flow",
		WithSigner("<yoursigner>"),
		WithArg("amount", 0.42),
		WithArg("to", "0x886f3aeaf848c535"),
	).Print()
}```

This will send 0.42 flow to me on mainnet. You need a go file with that content and a valid flow.json that is it



## Migrating from v1 api

You need to change your imports to be v2 and not v1

## Credits

This project is the successor of https://github.com/bjartek/go-with-the-flow
The v0 version of the code with a set of apis that is now deprecated is in https://github.com/bjartek/overflow/tree/v0
The v1 version of the code with a set of apis that is now deprecated is in https://github.com/bjartek/overflow/tree/v1

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Overflow will start an Overflow instance that panics if there are initialization errors Will read the following ENV vars as default: OVERFLOW_ENV : set to "mainnet|testnet|emulator|embedded", default embedded OVERFLOW_LOGGING: set from 0-3.
No description provided by the author
No description provided by the author
Send in an array of addresses as an argument.
Send an argument into a transaction The value is treated in the given way depending on type - cadence.Value is sent as straight argument - string argument are resolved into cadence.Value using flowkit - ofther values are converted to string with %v and resolved into cadence.Value using flowkit - if the type of the parameter is Address and the string you send in is a valid account in flow.json it will resolve.
sending in a timestamp as an arg is quite complicated, use this method with the name of the arg, the datestring and the given timezone to parse it at.
set a list of args as key, value in an interaction, see Arg for options you can pass in.
set arguments to the interaction from a map.
No description provided by the author
No description provided by the author
a helper to modify an event assertion if you have a sigle one and you want to change the value.
No description provided by the author
No description provided by the author
WithBasePath will change the standard basepath `.` to another folder.
No description provided by the author
No description provided by the author
No description provided by the author
filter out empty deposit and withdraw events.
print the emulator log.
No description provided by the author
No description provided by the author
filter out events that are printed.
set a filter for events.
set what block height to execute a script at! NB! if very old will not work on normal AN.
set what block height to execute a script at! NB! if very old will not work on normal AN.
set what block height to execute a script at! NB! if very old will not work on normal AN.
WithExistingEmulator will attach to an existing emulator, not deploying contracts and creating accounts.
WithTransactionFolderName will overwite the default script subdir for transactions `transactions`.
WithFlowConfig will set the path to one or more flow.json config files The default is ~/flow.json and ./flow.json.
Set the amount of flow for new account, default is 0.001.
print full meter verbose mode.
WithGas set the default gas limit, standard is 9999 (max).
set global filters to events.
automatically print interactions using the following options.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithNoLog will not log anything from results or flowkit logger.
alias for adding manual payload signers.
set an aditional authorizer that will sign the payload.
set payer, proposer authorizer as the signer.
set payer, proposer authorizer as the signer.
set the gas limit.
print meters as part of the transaction output line.
set the name of this interaction, for inline interactions this will be the entire name for file interactions they will be combined.
WithNetwork will start overflow with the given network.
Set custom network host if different from the one in flow.json since we cannot env substs there.
DoNotPrependNetworkToAccountNames will not prepend the name of the network to account names.
do not print events.
ignore global events filters defined on OverflowState.
No description provided by the author
force no printing for this interaction.
do not print meter.
Turn off storage fees.
No description provided by the author
If this option is used a panic will be called if an error occurs after an interaction is run.
set an aditional authorizer that will sign the payload.
print interactions using the following options.
alias for WithGLobalPrintOptions.
set the proposer.
set the propser to be the service account.
No description provided by the author
No description provided by the author
If this option is used a panic will be called if an error occurs after an interaction is run.
WithScriptFolderName will overwite the default script subdir for scripts `scripts`.
WithServiceAccountSuffix will set the suffix of the service account.
set payer, proposer authorizer as the signer.
set service account as payer, proposer, authorizer.
use the `cadence` struct tag to name a field or it will be given the lowercase name of the field.
use the `cadence` struct tag to name a field or it will be given the lowercase name of the field.
WithTransactionFolderName will overwite the default script subdir for transactions `transactions`.
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OverflowBuilder is the struct used to gather up configuration when building an overflow instance.
representing code with specification if parameters.
a type containing information about parameter types and orders.
OverflowEmulatorLogMessage a log message from the logrus implementation used in the flow emulator.
No description provided by the author
OverflowInteractionBuilder used to create a builder pattern for an interaction.
a type representing a meter that contains information about the inner workings of an interaction, only available on local emulator.
a type representing the accuumlated state in the builder the default setting is to print one line for each transaction with meter and all events.
OverflowResult represents the state after running an transaction.
result after running a script.
a type representing the raw solutions that contains all transactions, scripts, networks and warnings of any.
a type representing a merged solution that will be serialized as the json file for the npm module.
a network in the merged solution.
a type representing one network in a solution, so mainnet/testnet/emulator.
OverflowState contains information about how to Overflow is confitured and the current runnig state.
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

Overflow client is an interface with the most used v1 api methods for overflow.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Event parsing a type alias to an OverflowEventFilter to filter out all events with a given suffix and the fields with given suffixes.
No description provided by the author
a type holding all events that are emitted from a Transaction.
A function to customize the transaction builder.
type collecting computatationIntensities.
type collecting memoryIntensities.
OverflowOption and option function that you can send in to configure Overflow.
a type represneting seting an obtion in the printer builder.
a type used for composing scripts.
a type used for composing scripts.
a type to define a function used to compose Transaction interactions.
a type to define a function used to compose Transaction interactions.