Skip to content

Commit

Permalink
migrate to v2, fix warnigns
Browse files Browse the repository at this point in the history
  • Loading branch information
bjartek committed Feb 26, 2024
1 parent cfc1784 commit c7907ed
Show file tree
Hide file tree
Showing 29 changed files with 386 additions and 338 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: coveralls cover install-gotestsum test-report

coveralls:
go test --timeout 120s -coverprofile=profile.cov -covermode=atomic -coverpkg=github.com/bjartek/overflow -v ./...
go test --timeout 120s -coverprofile=profile.cov -covermode=atomic -coverpkg=github.com/bjartek/overflow/v2 -v ./...

cover: coveralls
go tool cover -html=profile.cov
Expand Down
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# 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:
Expand Down Expand Up @@ -46,7 +48,7 @@ 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
go get github.com/bjartek/overflow/v2
```

Then create a task file:
Expand All @@ -64,7 +66,7 @@ import (
"fmt"

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

func main() {
Expand Down Expand Up @@ -95,18 +97,12 @@ The following env vars are supported
- OVERFLOW_LOGGING: Set this to 0-4 to get increasing log


## Migrating from v0 api
## Migrating from v1 api

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

Please note the following if you migrate from an earlier version of overflow that was not tagged
- "github.com/bjartek/overflow/overflow" -> "github.com/bjartek/overflow"
- overflow.Overflow -> overflow.OverflowState
- on OverflowState Script -> InlineScript
- FlowTransationBuilder -> OverflowInteractionBuilder
- FlowArgumentsBuilder -> OverflowArgumentsBuilder
- Discord dependency is gone, if you need the code ask
- almost all of the v0 is deprecated in favor of the functional builders `Overflow` to set up the client and , `Tx`, `Script`, `FetchEvents` to interact with it

## 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
2 changes: 1 addition & 1 deletion doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package overflow_test

// importing overflow using "." will yield a cleaner DSL
import (
. "github.com/bjartek/overflow"
. "github.com/bjartek/overflow/v2"
)

var docOptions = WithGlobalPrintOptions(WithoutId())
Expand Down
6 changes: 3 additions & 3 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func (me OverflowEvents) GetStakeholders(stakeholders map[string][]string) map[s
}

type OverflowEvent struct {
Id string `json:"id"`
Fields map[string]interface{} `json:"fields"`
Addresses map[string][]string `json:"addresses"`
Id string `json:"id"`
TransactionId string `json:"transactionID"`
EventIndex uint32 `json:"eventIndex"`
Name string `json:"name"`
Addresses map[string][]string `json:"addresses"`
RawEvent cadence.Event `json:"rawEvent"`
EventIndex uint32 `json:"eventIndex"`
}

// Check if an event exist in the other events
Expand Down
26 changes: 13 additions & 13 deletions event_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ type InMemoryProgressKeeper struct {
Progress int64
}

func (self *InMemoryProgressKeeper) ReadProgress() (int64, error) {
return self.Progress, nil
func (impk *InMemoryProgressKeeper) ReadProgress() (int64, error) {
return impk.Progress, nil
}

func (self *InMemoryProgressKeeper) WriteProgress(progress int64) error {
self.Progress = progress
func (impk *InMemoryProgressKeeper) WriteProgress(progress int64) error {
impk.Progress = progress
return nil
}

// OverflowEventFetcherBuilder builder to hold info about eventhook context.
type OverflowEventFetcherBuilder struct {
Ctx context.Context
ProgressRW ProgressReaderWriter
OverflowState *OverflowState
EventsAndIgnoreFields OverflowEventFilter
ProgressFile string
FromIndex int64
EndAtCurrentHeight bool
EndIndex uint64
ProgressFile string
ProgressRW ProgressReaderWriter
NumberOfWorkers int
EventBatchSize uint64
EndAtCurrentHeight bool
ReturnWriterFunction bool
}

Expand All @@ -73,12 +73,12 @@ func (o *OverflowState) buildEventInteraction(opts ...OverflowEventFetcherOption
type ProgressWriterFunction func() error

type EventFetcherResult struct {
Events []OverflowPastEvent
Error error
State *OverflowEventFetcherBuilder
ProgressWriteFunction ProgressWriterFunction
Events []OverflowPastEvent
From int64
To uint64
ProgressWriteFunction ProgressWriterFunction
}

func (efr EventFetcherResult) String() string {
Expand Down Expand Up @@ -339,19 +339,19 @@ func WithReturnProgressWriter() OverflowEventFetcherOption {

// a type to represent an event that we get from FetchEvents
type OverflowPastEvent struct {
Name string `json:"name"`
BlockHeight uint64 `json:"blockHeight,omitempty"`
BlockID string `json:"blockID,omnitEmpty"`
Time time.Time `json:"time,omitempty"`
Name string `json:"name"`
BlockID string `json:"blockID,omitempty"`
Event OverflowEvent `json:"event"`
BlockHeight uint64 `json:"blockHeight,omitempty"`
}

type OverflowGraffleEvent struct {
EventDate time.Time `json:"eventDate"`
BlockEventData map[string]interface{} `json:"blockEventData"`
FlowEventID string `json:"flowEventId"`
FlowTransactionID string `json:"flowTransactionId"`
ID string `json:"id"`
BlockEventData map[string]interface{} `json:"blockEventData"`
}

func (e OverflowPastEvent) ToGraffleEvent() OverflowGraffleEvent {
Expand Down
3 changes: 1 addition & 2 deletions example/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"os"
"testing"

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

// we set the shared overflow test struct that will reset to known setup state after each test
var ot *overflow.OverflowTest

func TestMain(m *testing.M) {

var err error
ot, err = overflow.SetupTest([]overflow.OverflowOption{overflow.WithCoverageReport()}, func(o *overflow.OverflowState) error {
o.MintFlowTokens("first", 1000.0)
Expand Down
6 changes: 2 additions & 4 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

func (o *OverflowState) GenerateStub(network, filePath string, standalone bool) (string, error) {

solution, err := o.ParseAll()
if err != nil {
return "", err
Expand All @@ -24,7 +23,7 @@ func (o *OverflowState) GenerateStub(network, filePath string, standalone bool)
commandName = "Script"
}
if interaction == nil {
return "", fmt.Errorf("Could not find interaction of type %s with name %s", commandName, interaction)
return "", fmt.Errorf("could not find interaction of type %s with name %s", commandName, interaction)
}
lines := []string{
fmt.Sprintf(` o.%s("%s",`, commandName, interactionName),
Expand All @@ -51,12 +50,11 @@ func (o *OverflowState) GenerateStub(network, filePath string, standalone bool)
return fmt.Sprintf(`package main
import (
. "github.com/bjartek/overflow"
. "github.com/bjartek/overflow/v2"
)
func main() {
o := Overflow(WithNetwork("%s"), WithPrintResults())
%s
}`, network, stub), nil

}
5 changes: 1 addition & 4 deletions generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
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
*/
func TestGenerate(t *testing.T) {

o, err := OverflowTesting()
require.NoError(t, err)
t.Run("script", func(t *testing.T) {
Expand Down Expand Up @@ -43,7 +42,7 @@ func TestGenerate(t *testing.T) {
assert.Equal(t, `package main
import (
. "github.com/bjartek/overflow"
. "github.com/bjartek/overflow/v2"
)
func main() {
Expand All @@ -53,7 +52,5 @@ func main() {
WithArg("test", <>), //String
)
}`, stub)

})

}
Loading

0 comments on commit c7907ed

Please sign in to comment.