diff --git a/event_fetcher.go b/event_fetcher.go deleted file mode 100644 index ec71689..0000000 --- a/event_fetcher.go +++ /dev/null @@ -1,405 +0,0 @@ -package overflow - -import ( - "context" - "encoding/json" - "fmt" - "sort" - "strings" - "time" - - "github.com/onflow/flowkit/v2" -) - -// Event fetching -// -// A function to customize the transaction builder -type OverflowEventFetcherOption func(*OverflowEventFetcherBuilder) - -type ProgressReaderWriter interface { - /// can return 0 if we do not have any progress thus far - ReadProgress() (int64, error) - WriteProgress(progress int64) error -} - -type InMemoryProgressKeeper struct { - Progress int64 -} - -func (impk *InMemoryProgressKeeper) ReadProgress() (int64, error) { - return impk.Progress, nil -} - -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 - EndIndex uint64 - NumberOfWorkers int - EventBatchSize uint64 - EndAtCurrentHeight bool - ReturnWriterFunction bool -} - -// Build an event fetcher builder from the sent in options -func (o *OverflowState) buildEventInteraction(opts ...OverflowEventFetcherOption) *OverflowEventFetcherBuilder { - e := &OverflowEventFetcherBuilder{ - Ctx: context.Background(), - OverflowState: o, - EventsAndIgnoreFields: OverflowEventFilter{}, - EndAtCurrentHeight: true, - FromIndex: -10, - ProgressFile: "", - EventBatchSize: 250, - NumberOfWorkers: 20, - ReturnWriterFunction: false, - } - - for _, opt := range opts { - opt(e) - } - return e -} - -type ProgressWriterFunction func() error - -type EventFetcherResult struct { - Error error - State *OverflowEventFetcherBuilder - ProgressWriteFunction ProgressWriterFunction - Events []OverflowPastEvent - From int64 - To uint64 -} - -func (efr EventFetcherResult) String() string { - events := []string{} - for event := range efr.State.EventsAndIgnoreFields { - events = append(events, event) - } - eventString := strings.Join(events, ",") - return fmt.Sprintf("Fetched number=%d of events within from=%d block to=%d for events=%s\n", len(efr.Events), efr.From, efr.To, eventString) -} - -// FetchEvents using the given options -func (o *OverflowState) FetchEventsWithResult(opts ...OverflowEventFetcherOption) EventFetcherResult { - e := o.buildEventInteraction(opts...) - - res := EventFetcherResult{State: e} - // if we have a progress file read the value from it and set it as oldHeight - if e.ProgressFile != "" { - - present, err := exists(e.ProgressFile) - if err != nil { - res.Error = err - return res - } - - if !present { - err := writeProgressToFile(e.ProgressFile, 0) - if err != nil { - res.Error = fmt.Errorf("could not create initial progress file %v", err) - return res - } - - e.FromIndex = 0 - } else { - oldHeight, err := readProgressFromFile(e.ProgressFile) - if err != nil { - res.Error = fmt.Errorf("could not parse progress file as block height %v", err) - return res - } - e.FromIndex = oldHeight - } - } else if e.ProgressRW != nil { - oldHeight, err := e.ProgressRW.ReadProgress() - if err != nil { - res.Error = fmt.Errorf("could not parse progress file as block height %v", err) - return res - } - e.FromIndex = oldHeight - } - - endIndex := e.EndIndex - if e.EndAtCurrentHeight { - blockHeight, err := e.OverflowState.GetLatestBlock(e.Ctx) - if err != nil { - res.Error = err - return res - } - endIndex = blockHeight.Height - } - - fromIndex := e.FromIndex - // if we have a negative fromIndex is is relative to endIndex - if e.FromIndex <= 0 { - fromIndex = int64(endIndex) + e.FromIndex - } - - if fromIndex < 0 { - res.Error = fmt.Errorf("FromIndex is negative") - return res - } - - var events []string - for key := range e.EventsAndIgnoreFields { - events = append(events, key) - } - - if uint64(fromIndex) > endIndex { - return res - } - ew := &flowkit.EventWorker{ - Count: e.NumberOfWorkers, - BlocksPerWorker: e.EventBatchSize, - } - blockEvents, err := e.OverflowState.Flowkit.GetEvents(e.Ctx, events, uint64(fromIndex), endIndex, ew) - if err != nil { - res.Error = err - return res - } - - formatedEvents := []OverflowPastEvent{} - for _, blockEvent := range blockEvents { - events, _ := o.ParseEvents(blockEvent.Events, "") - for name, eventList := range events { - for _, instance := range eventList { - formatedEvents = append(formatedEvents, OverflowPastEvent{ - Name: name, - Time: blockEvent.BlockTimestamp, - BlockHeight: blockEvent.Height, - BlockID: blockEvent.BlockID.String(), - Event: instance, - }) - } - } - } - - if e.ProgressFile != "" { - - progressWriter := func() error { - return writeProgressToFile(e.ProgressFile, int64(endIndex+1)) - } - if e.ReturnWriterFunction { - res.ProgressWriteFunction = progressWriter - } else { - err := progressWriter() - if err != nil { - res.Error = fmt.Errorf("could not write progress to file %v", err) - return res - } - } - } else if e.ProgressRW != nil { - progressWriter := func() error { - return e.ProgressRW.WriteProgress(int64(endIndex + 1)) - } - - if e.ReturnWriterFunction { - res.ProgressWriteFunction = progressWriter - } else { - err := progressWriter() - if err != nil { - res.Error = fmt.Errorf("could not write progress to file %v", err) - return res - } - } - } - sort.Slice(formatedEvents, func(i, j int) bool { - return formatedEvents[i].BlockHeight < formatedEvents[j].BlockHeight - }) - - res.Events = formatedEvents - res.From = fromIndex - res.To = endIndex - return res -} - -// FetchEvents using the given options -func (o *OverflowState) FetchEvents(opts ...OverflowEventFetcherOption) ([]OverflowPastEvent, error) { - res := o.FetchEventsWithResult(opts...) - return res.Events, res.Error -} - -// Set the Workers size for FetchEvents -func WithEventFetcherContext(ctx context.Context) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.Ctx = ctx - } -} - -// Set the Workers size for FetchEvents -func WithWorkers(workers int) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.NumberOfWorkers = workers - } -} - -// Set the batch size for FetchEvents -func WithBatchSize(size uint64) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.EventBatchSize = size - } -} - -// set that we want to fetch an event and all its fields -func WithEvent(eventName string) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.EventsAndIgnoreFields[eventName] = []string{} - } -} - -// set that we want the following events and ignoring the fields mentioned -func WithEventIgnoringField(eventName string, ignoreFields []string) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.EventsAndIgnoreFields[eventName] = ignoreFields - } -} - -// set the start height to use -func WithStartHeight(blockHeight int64) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.FromIndex = blockHeight - } -} - -// set the from index to use alias to WithStartHeight -func WithFromIndex(blockHeight int64) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.FromIndex = blockHeight - } -} - -// set the end index to use -func WithEndIndex(blockHeight uint64) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.EndIndex = blockHeight - e.EndAtCurrentHeight = false - } -} - -// set the relative list of blocks to fetch events from -func WithLastBlocks(number uint64) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.EndAtCurrentHeight = true - e.FromIndex = -int64(number) - } -} - -// fetch events until theg given height alias to WithEndHeight -func WithUntilBlock(blockHeight uint64) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.EndIndex = blockHeight - e.EndAtCurrentHeight = false - } -} - -// set the end index to the current height -func WithUntilCurrentBlock() OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.EndAtCurrentHeight = true - e.EndIndex = 0 - } -} - -// track what block we have read since last run in a file -func WithTrackProgressIn(fileName string) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.ProgressFile = fileName - e.EndIndex = 0 - e.FromIndex = 0 - e.EndAtCurrentHeight = true - } -} - -// track what block we have read since last run in a file -func WithTrackProgress(progressReaderWriter ProgressReaderWriter) OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.ProgressRW = progressReaderWriter - e.EndIndex = 0 - e.FromIndex = 0 - e.EndAtCurrentHeight = true - } -} - -// track what block we have read since last run in a file -func WithReturnProgressWriter() OverflowEventFetcherOption { - return func(e *OverflowEventFetcherBuilder) { - e.ReturnWriterFunction = true - } -} - -// a type to represent an event that we get from FetchEvents -type OverflowPastEvent struct { - 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"` -} - -func (e OverflowPastEvent) ToGraffleEvent() OverflowGraffleEvent { - return OverflowGraffleEvent{ - EventDate: e.Time, - FlowEventID: e.Name, - ID: "unknown", - FlowTransactionID: e.Event.TransactionId, - BlockEventData: e.Event.Fields, - } -} - -func (e OverflowGraffleEvent) MarshalAs(marshalTo interface{}) error { - bytes, err := json.Marshal(e) - if err != nil { - return err - } - - err = json.Unmarshal(bytes, marshalTo) - if err != nil { - return err - } - return nil -} - -func (e OverflowPastEvent) MarshalAs(marshalTo interface{}) error { - bytes, err := json.Marshal(e) - if err != nil { - return err - } - - err = json.Unmarshal(bytes, marshalTo) - if err != nil { - return err - } - return nil -} - -// String pretty print an event as a String -func (e OverflowPastEvent) String() string { - j, err := json.MarshalIndent(e, "", " ") - if err != nil { - panic(err) - } - return string(j) -} - -// get the given field as an uint64 -func (e OverflowPastEvent) GetFieldAsUInt64(field string) uint64 { - return e.Event.Fields[field].(uint64) -} diff --git a/event_fetcher_integration_test.go b/event_fetcher_integration_test.go deleted file mode 100644 index 4223c0b..0000000 --- a/event_fetcher_integration_test.go +++ /dev/null @@ -1,177 +0,0 @@ -package overflow - -import ( - "io/fs" - "os" - "testing" - "time" - - "github.com/hexops/autogold" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func startOverflowAndMintTokens(t *testing.T) *OverflowState { - t.Helper() - o, err := OverflowTesting() - require.NoError(t, err) - require.NotNil(t, o) - result := o.Tx("mint_tokens", WithSignerServiceAccount(), WithArg("recipient", "first"), WithArg("amount", 100.0)) - assert.NoError(t, result.Err) - return o - -} - -type MarketEvent struct { - EventDate time.Time `json:"eventDate"` - FlowEventID string `json:"flowEventId"` - FlowTransactionID string `json:"flowTransactionId"` - ID string `json:"id"` - BlockEventData struct { - Amount float64 `json:"amount"` - } `json:"blockEventData"` -} - -func TestIntegrationEventFetcher(t *testing.T) { - - t.Run("Test that from index cannot be negative", func(t *testing.T) { - _, err := startOverflowAndMintTokens(t).FetchEvents( - WithEndIndex(2), - WithFromIndex(-10), - WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), - ) - assert.Error(t, err) - assert.Contains(t, err.Error(), "FromIndex is negative") - }) - - t.Run("Fetch last events", func(t *testing.T) { - ev, err := startOverflowAndMintTokens(t).FetchEvents( - WithLastBlocks(2), - WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), - ) - assert.NoError(t, err) - assert.Equal(t, 2, len(ev)) - }) - - t.Run("Fetch last events and sort them ", func(t *testing.T) { - o := startOverflowAndMintTokens(t) - result := o.Tx("mint_tokens", WithSignerServiceAccount(), WithArg("recipient", "first"), WithArg("amount", "100.0")) - assert.NoError(t, result.Err) - ev, err := o.FetchEvents( - WithLastBlocks(3), - WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), - ) - assert.NoError(t, err) - assert.Equal(t, 3, len(ev)) - assert.True(t, ev[0].BlockHeight < ev[1].BlockHeight) - }) - - t.Run("Fetch last write progress file", func(t *testing.T) { - ev, err := startOverflowAndMintTokens(t).FetchEvents( - WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), - WithTrackProgressIn("progress"), - ) - defer os.Remove("progress") - assert.NoError(t, err) - assert.Equal(t, 1, len(ev)) - assert.Contains(t, ev[0].String(), "10") - }) - - t.Run("should fail reading invalid progress from file", func(t *testing.T) { - err := os.WriteFile("progress", []byte("invalid"), fs.ModePerm) - assert.NoError(t, err) - - _, err = startOverflowAndMintTokens(t).FetchEvents( - WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), - WithTrackProgressIn("progress"), - ) - defer os.Remove("progress") - assert.Error(t, err) - assert.Equal(t, "could not parse progress file as block height strconv.ParseInt: parsing \"invalid\": invalid syntax", err.Error()) - }) - - t.Run("Fetch last write progress file that exists and marshal events", func(t *testing.T) { - - err := os.WriteFile("progress", []byte("1"), fs.ModePerm) - assert.NoError(t, err) - - ev, err := startOverflowAndMintTokens(t).FetchEvents( - WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), - WithTrackProgressIn("progress"), - ) - defer os.Remove("progress") - assert.NoError(t, err) - assert.Equal(t, 3, len(ev)) - event := ev[0] - - graffleEvent := event.ToGraffleEvent() - - var eventMarshal map[string]interface{} - assert.NoError(t, event.MarshalAs(&eventMarshal)) - assert.NotEmpty(t, eventMarshal) - - autogold.Equal(t, graffleEvent.BlockEventData, autogold.Name("graffle-event")) - var marshalTo MarketEvent - assert.NoError(t, graffleEvent.MarshalAs(&marshalTo)) - assert.Equal(t, float64(10), marshalTo.BlockEventData.Amount) - }) - - t.Run("Fetch last write progress in memory that exists and marshal events", func(t *testing.T) { - - imr := &InMemoryProgressKeeper{Progress: 1} - - ev, err := startOverflowAndMintTokens(t).FetchEvents( - WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), - WithTrackProgress(imr), - ) - assert.NoError(t, err) - assert.Equal(t, 3, len(ev)) - event := ev[0] - - graffleEvent := event.ToGraffleEvent() - - var eventMarshal map[string]interface{} - assert.NoError(t, event.MarshalAs(&eventMarshal)) - assert.NotEmpty(t, eventMarshal) - - autogold.Equal(t, graffleEvent.BlockEventData, autogold.Name("graffle-event")) - var marshalTo MarketEvent - assert.NoError(t, graffleEvent.MarshalAs(&marshalTo)) - assert.Equal(t, float64(10), marshalTo.BlockEventData.Amount) - - assert.Equal(t, int64(7), imr.Progress) - }) - - t.Run("Return progress writer ", func(t *testing.T) { - progressFile := "progress" - - err := writeProgressToFile(progressFile, 0) - require.NoError(t, err) - res := startOverflowAndMintTokens(t).FetchEventsWithResult( - WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), - WithTrackProgressIn(progressFile), - WithReturnProgressWriter(), - ) - require.NoError(t, res.Error) - want := autogold.Want("eventProgress", `Fetched number=1 of events within from=6 block to=6 for events=A.0ae53cb6e3f42a79.FlowToken.TokensMinted -`) - want.Equal(t, res.String()) - - progress, err := readProgressFromFile(progressFile) - require.NoError(t, err) - assert.Equal(t, int64(0), progress) - - err = res.ProgressWriteFunction() - require.NoError(t, err) - - progress, err = readProgressFromFile(progressFile) - require.NoError(t, err) - assert.Equal(t, int64(7), progress) - - ev := res.Events - defer os.Remove(progressFile) - assert.Equal(t, 1, len(ev)) - assert.Contains(t, ev[0].String(), "100") - }) - -} diff --git a/event_fetcher_test.go b/event_fetcher_test.go deleted file mode 100644 index a658c07..0000000 --- a/event_fetcher_test.go +++ /dev/null @@ -1,84 +0,0 @@ -package overflow - -import ( - "os" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestEventFetcher(t *testing.T) { - - g, err := OverflowTesting() - require.NoError(t, err) - require.NotNil(t, g) - - t.Run("Start argument", func(t *testing.T) { - ef := g.buildEventInteraction(WithStartHeight(100)) - assert.Equal(t, ef.FromIndex, int64(100)) - }) - - t.Run("From argument", func(t *testing.T) { - ef := g.buildEventInteraction(WithFromIndex(100)) - assert.Equal(t, ef.FromIndex, int64(100)) - }) - - t.Run("End argument", func(t *testing.T) { - ef := g.buildEventInteraction(WithEndIndex(100)) - assert.Equal(t, ef.EndIndex, uint64(100)) - assert.False(t, ef.EndAtCurrentHeight) - }) - - t.Run("Until argument", func(t *testing.T) { - ef := g.buildEventInteraction(WithUntilBlock(100)) - assert.Equal(t, ef.EndIndex, uint64(100)) - assert.False(t, ef.EndAtCurrentHeight) - }) - - t.Run("Until current argument", func(t *testing.T) { - ef := g.buildEventInteraction(WithUntilCurrentBlock()) - assert.Equal(t, ef.EndIndex, uint64(0)) - assert.True(t, ef.EndAtCurrentHeight) - }) - - t.Run("workers argument", func(t *testing.T) { - ef := g.buildEventInteraction(WithWorkers(100)) - assert.Equal(t, ef.NumberOfWorkers, 100) - }) - - t.Run("batch size argument", func(t *testing.T) { - ef := g.buildEventInteraction(WithBatchSize(100)) - assert.Equal(t, ef.EventBatchSize, uint64(100)) - }) - - t.Run("event ignoring field argument", func(t *testing.T) { - ef := g.buildEventInteraction(WithEventIgnoringField("foo", []string{"bar", "baz"})) - assert.Equal(t, ef.EventsAndIgnoreFields["foo"], []string{"bar", "baz"}) - }) - - t.Run("failed reading invalid file", func(t *testing.T) { - _, err := readProgressFromFile("boing.boinb") - assert.Error(t, err) - assert.Contains(t, err.Error(), "ProgressFile is not valid open boing.boinb") - }) - - t.Run("Cannot write to file that is dir", func(t *testing.T) { - err := os.Mkdir("foo", os.ModeDir) - assert.NoError(t, err) - defer os.RemoveAll("foo") - - err = writeProgressToFile("foo", 1) - assert.Error(t, err) - assert.Contains(t, err.Error(), "foo: is a directory") - - }) - - t.Run("Return false if cannot find event", func(t *testing.T) { - - events := []OverflowEvent{{Fields: map[string]interface{}{"bar": "baz"}}} - event := OverflowEvent{Fields: map[string]interface{}{"baz": "bar"}} - - assert.False(t, event.ExistIn(events)) - }) -} diff --git a/event_integration_test.go b/event_integration_test.go deleted file mode 100644 index 2424848..0000000 --- a/event_integration_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package overflow - -import ( - "io/fs" - "os" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestIntegrationEvents(t *testing.T) { - t.Run("Test that from index cannot be negative", func(t *testing.T) { - g, err := OverflowTesting() - require.NoError(t, err) - require.NotNil(t, g) - - g.Tx("mint_tokens", - WithSignerServiceAccount(), - WithArg("recipient", "first"), - WithArg("amount", 100.0), - ).AssertSuccess(t). - AssertEventCount(t, 4) - - _, err = g.FetchEvents( - WithEndIndex(2), - WithFromIndex(-10), - WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), - ) - assert.Error(t, err) - assert.Contains(t, err.Error(), "FromIndex is negative") - }) - - t.Run("Fetch last events", func(t *testing.T) { - g, err := OverflowTesting() - require.NoError(t, err) - g.Tx("mint_tokens", - WithSignerServiceAccount(), - WithArg("recipient", "first"), - WithArg("amount", 100.0), - ).AssertSuccess(t). - AssertEventCount(t, 4) - ev, err := g.FetchEvents(WithLastBlocks(2), WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted")) - assert.NoError(t, err) - assert.Equal(t, 2, len(ev)) - }) - - t.Run("Fetch last events and sort them ", func(t *testing.T) { - g, err := OverflowTesting() - require.NoError(t, err) - g.Tx("mint_tokens", - WithSignerServiceAccount(), - WithArg("recipient", "first"), - WithArg("amount", 100.0), - ).AssertSuccess(t). - AssertEventCount(t, 4) - - g.Tx("mint_tokens", - WithSignerServiceAccount(), - WithArg("recipient", "first"), - WithArg("amount", 100.0), - ).AssertSuccess(t). - AssertEventCount(t, 4) - - ev, err := g.FetchEvents(WithLastBlocks(2), WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted")) - assert.NoError(t, err) - assert.Equal(t, 2, len(ev)) - assert.True(t, ev[0].BlockHeight < ev[1].BlockHeight) - }) - - t.Run("Fetch last write progress file", func(t *testing.T) { - g, err := OverflowTesting() - require.NoError(t, err) - g.Tx("mint_tokens", - WithSignerServiceAccount(), - WithArg("recipient", "first"), - WithArg("amount", 100.0), - ).AssertSuccess(t). - AssertEventCount(t, 4) - - ev, err := g.FetchEvents(WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), WithTrackProgressIn("progress")) - defer os.Remove("progress") - assert.NoError(t, err) - assert.Equal(t, 1, len(ev)) - }) - - t.Run("should fail reading invalid progress from file", func(t *testing.T) { - err := os.WriteFile("progress", []byte("invalid"), fs.ModePerm) - assert.NoError(t, err) - - g, err := OverflowTesting() - require.NoError(t, err) - - _, err = g.FetchEvents(WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), WithTrackProgressIn("progress")) - defer os.Remove("progress") - assert.Error(t, err) - assert.Equal(t, "could not parse progress file as block height strconv.ParseInt: parsing \"invalid\": invalid syntax", err.Error()) - }) - - t.Run("Fetch last write progress file that exists", func(t *testing.T) { - err := os.WriteFile("progress", []byte("1"), fs.ModePerm) - assert.NoError(t, err) - - g, err := OverflowTesting() - assert.NoError(t, err) - g.Tx("mint_tokens", - WithSignerServiceAccount(), - WithArg("recipient", "first"), - WithArg("amount", 100.0), - ).AssertSuccess(t). - AssertEventCount(t, 4) - - ev, err := g.FetchEvents(WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), WithTrackProgressIn("progress")) - defer os.Remove("progress") - assert.NoError(t, err) - assert.Equal(t, 3, len(ev)) - }) -} diff --git a/mocks/OverflowBetaClient.go b/mocks/OverflowBetaClient.go index c34680f..79957a3 100644 --- a/mocks/OverflowBetaClient.go +++ b/mocks/OverflowBetaClient.go @@ -385,48 +385,161 @@ func (_c *OverflowBetaClient_DownloadImageAndUploadAsDataUrl_Call) RunAndReturn( return _c } -// FetchEventsWithResult provides a mock function with given fields: opts -func (_m *OverflowBetaClient) FetchEventsWithResult(opts ...overflow.OverflowEventFetcherOption) overflow.EventFetcherResult { +// FillUpStorage provides a mock function with given fields: accountName +func (_m *OverflowBetaClient) FillUpStorage(accountName string) *overflow.OverflowState { + ret := _m.Called(accountName) + + if len(ret) == 0 { + panic("no return value specified for FillUpStorage") + } + + var r0 *overflow.OverflowState + if rf, ok := ret.Get(0).(func(string) *overflow.OverflowState); ok { + r0 = rf(accountName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*overflow.OverflowState) + } + } + + return r0 +} + +// OverflowBetaClient_FillUpStorage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FillUpStorage' +type OverflowBetaClient_FillUpStorage_Call struct { + *mock.Call +} + +// FillUpStorage is a helper method to define mock.On call +// - accountName string +func (_e *OverflowBetaClient_Expecter) FillUpStorage(accountName interface{}) *OverflowBetaClient_FillUpStorage_Call { + return &OverflowBetaClient_FillUpStorage_Call{Call: _e.mock.On("FillUpStorage", accountName)} +} + +func (_c *OverflowBetaClient_FillUpStorage_Call) Run(run func(accountName string)) *OverflowBetaClient_FillUpStorage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *OverflowBetaClient_FillUpStorage_Call) Return(_a0 *overflow.OverflowState) *OverflowBetaClient_FillUpStorage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowBetaClient_FillUpStorage_Call) RunAndReturn(run func(string) *overflow.OverflowState) *OverflowBetaClient_FillUpStorage_Call { + _c.Call.Return(run) + return _c +} + +// FlixScript provides a mock function with given fields: filename, opts +func (_m *OverflowBetaClient) FlixScript(filename string, opts ...overflow.OverflowInteractionOption) *overflow.OverflowScriptResult { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] } var _ca []interface{} + _ca = append(_ca, filename) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FlixScript") + } + + var r0 *overflow.OverflowScriptResult + if rf, ok := ret.Get(0).(func(string, ...overflow.OverflowInteractionOption) *overflow.OverflowScriptResult); ok { + r0 = rf(filename, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*overflow.OverflowScriptResult) + } + } + + return r0 +} + +// OverflowBetaClient_FlixScript_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixScript' +type OverflowBetaClient_FlixScript_Call struct { + *mock.Call +} + +// FlixScript is a helper method to define mock.On call +// - filename string +// - opts ...overflow.OverflowInteractionOption +func (_e *OverflowBetaClient_Expecter) FlixScript(filename interface{}, opts ...interface{}) *OverflowBetaClient_FlixScript_Call { + return &OverflowBetaClient_FlixScript_Call{Call: _e.mock.On("FlixScript", + append([]interface{}{filename}, opts...)...)} +} + +func (_c *OverflowBetaClient_FlixScript_Call) Run(run func(filename string, opts ...overflow.OverflowInteractionOption)) *OverflowBetaClient_FlixScript_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *OverflowBetaClient_FlixScript_Call) Return(_a0 *overflow.OverflowScriptResult) *OverflowBetaClient_FlixScript_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowBetaClient_FlixScript_Call) RunAndReturn(run func(string, ...overflow.OverflowInteractionOption) *overflow.OverflowScriptResult) *OverflowBetaClient_FlixScript_Call { + _c.Call.Return(run) + return _c +} + +// FlixScriptFN provides a mock function with given fields: outerOpts +func (_m *OverflowBetaClient) FlixScriptFN(outerOpts ...overflow.OverflowInteractionOption) overflow.OverflowScriptFunction { + _va := make([]interface{}, len(outerOpts)) + for _i := range outerOpts { + _va[_i] = outerOpts[_i] + } + var _ca []interface{} _ca = append(_ca, _va...) ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for FetchEventsWithResult") + panic("no return value specified for FlixScriptFN") } - var r0 overflow.EventFetcherResult - if rf, ok := ret.Get(0).(func(...overflow.OverflowEventFetcherOption) overflow.EventFetcherResult); ok { - r0 = rf(opts...) + var r0 overflow.OverflowScriptFunction + if rf, ok := ret.Get(0).(func(...overflow.OverflowInteractionOption) overflow.OverflowScriptFunction); ok { + r0 = rf(outerOpts...) } else { - r0 = ret.Get(0).(overflow.EventFetcherResult) + if ret.Get(0) != nil { + r0 = ret.Get(0).(overflow.OverflowScriptFunction) + } } return r0 } -// OverflowBetaClient_FetchEventsWithResult_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FetchEventsWithResult' -type OverflowBetaClient_FetchEventsWithResult_Call struct { +// OverflowBetaClient_FlixScriptFN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixScriptFN' +type OverflowBetaClient_FlixScriptFN_Call struct { *mock.Call } -// FetchEventsWithResult is a helper method to define mock.On call -// - opts ...overflow.OverflowEventFetcherOption -func (_e *OverflowBetaClient_Expecter) FetchEventsWithResult(opts ...interface{}) *OverflowBetaClient_FetchEventsWithResult_Call { - return &OverflowBetaClient_FetchEventsWithResult_Call{Call: _e.mock.On("FetchEventsWithResult", - append([]interface{}{}, opts...)...)} +// FlixScriptFN is a helper method to define mock.On call +// - outerOpts ...overflow.OverflowInteractionOption +func (_e *OverflowBetaClient_Expecter) FlixScriptFN(outerOpts ...interface{}) *OverflowBetaClient_FlixScriptFN_Call { + return &OverflowBetaClient_FlixScriptFN_Call{Call: _e.mock.On("FlixScriptFN", + append([]interface{}{}, outerOpts...)...)} } -func (_c *OverflowBetaClient_FetchEventsWithResult_Call) Run(run func(opts ...overflow.OverflowEventFetcherOption)) *OverflowBetaClient_FetchEventsWithResult_Call { +func (_c *OverflowBetaClient_FlixScriptFN_Call) Run(run func(outerOpts ...overflow.OverflowInteractionOption)) *OverflowBetaClient_FlixScriptFN_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]overflow.OverflowEventFetcherOption, len(args)-0) + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-0) for i, a := range args[0:] { if a != nil { - variadicArgs[i] = a.(overflow.OverflowEventFetcherOption) + variadicArgs[i] = a.(overflow.OverflowInteractionOption) } } run(variadicArgs...) @@ -434,60 +547,262 @@ func (_c *OverflowBetaClient_FetchEventsWithResult_Call) Run(run func(opts ...ov return _c } -func (_c *OverflowBetaClient_FetchEventsWithResult_Call) Return(_a0 overflow.EventFetcherResult) *OverflowBetaClient_FetchEventsWithResult_Call { +func (_c *OverflowBetaClient_FlixScriptFN_Call) Return(_a0 overflow.OverflowScriptFunction) *OverflowBetaClient_FlixScriptFN_Call { _c.Call.Return(_a0) return _c } -func (_c *OverflowBetaClient_FetchEventsWithResult_Call) RunAndReturn(run func(...overflow.OverflowEventFetcherOption) overflow.EventFetcherResult) *OverflowBetaClient_FetchEventsWithResult_Call { +func (_c *OverflowBetaClient_FlixScriptFN_Call) RunAndReturn(run func(...overflow.OverflowInteractionOption) overflow.OverflowScriptFunction) *OverflowBetaClient_FlixScriptFN_Call { _c.Call.Return(run) return _c } -// FillUpStorage provides a mock function with given fields: accountName -func (_m *OverflowBetaClient) FillUpStorage(accountName string) *overflow.OverflowState { - ret := _m.Called(accountName) +// FlixScriptFileNameFN provides a mock function with given fields: filename, outerOpts +func (_m *OverflowBetaClient) FlixScriptFileNameFN(filename string, outerOpts ...overflow.OverflowInteractionOption) overflow.OverflowScriptOptsFunction { + _va := make([]interface{}, len(outerOpts)) + for _i := range outerOpts { + _va[_i] = outerOpts[_i] + } + var _ca []interface{} + _ca = append(_ca, filename) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for FillUpStorage") + panic("no return value specified for FlixScriptFileNameFN") } - var r0 *overflow.OverflowState - if rf, ok := ret.Get(0).(func(string) *overflow.OverflowState); ok { - r0 = rf(accountName) + var r0 overflow.OverflowScriptOptsFunction + if rf, ok := ret.Get(0).(func(string, ...overflow.OverflowInteractionOption) overflow.OverflowScriptOptsFunction); ok { + r0 = rf(filename, outerOpts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*overflow.OverflowState) + r0 = ret.Get(0).(overflow.OverflowScriptOptsFunction) } } return r0 } -// OverflowBetaClient_FillUpStorage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FillUpStorage' -type OverflowBetaClient_FillUpStorage_Call struct { +// OverflowBetaClient_FlixScriptFileNameFN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixScriptFileNameFN' +type OverflowBetaClient_FlixScriptFileNameFN_Call struct { *mock.Call } -// FillUpStorage is a helper method to define mock.On call -// - accountName string -func (_e *OverflowBetaClient_Expecter) FillUpStorage(accountName interface{}) *OverflowBetaClient_FillUpStorage_Call { - return &OverflowBetaClient_FillUpStorage_Call{Call: _e.mock.On("FillUpStorage", accountName)} +// FlixScriptFileNameFN is a helper method to define mock.On call +// - filename string +// - outerOpts ...overflow.OverflowInteractionOption +func (_e *OverflowBetaClient_Expecter) FlixScriptFileNameFN(filename interface{}, outerOpts ...interface{}) *OverflowBetaClient_FlixScriptFileNameFN_Call { + return &OverflowBetaClient_FlixScriptFileNameFN_Call{Call: _e.mock.On("FlixScriptFileNameFN", + append([]interface{}{filename}, outerOpts...)...)} } -func (_c *OverflowBetaClient_FillUpStorage_Call) Run(run func(accountName string)) *OverflowBetaClient_FillUpStorage_Call { +func (_c *OverflowBetaClient_FlixScriptFileNameFN_Call) Run(run func(filename string, outerOpts ...overflow.OverflowInteractionOption)) *OverflowBetaClient_FlixScriptFileNameFN_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(args[0].(string), variadicArgs...) }) return _c } -func (_c *OverflowBetaClient_FillUpStorage_Call) Return(_a0 *overflow.OverflowState) *OverflowBetaClient_FillUpStorage_Call { +func (_c *OverflowBetaClient_FlixScriptFileNameFN_Call) Return(_a0 overflow.OverflowScriptOptsFunction) *OverflowBetaClient_FlixScriptFileNameFN_Call { _c.Call.Return(_a0) return _c } -func (_c *OverflowBetaClient_FillUpStorage_Call) RunAndReturn(run func(string) *overflow.OverflowState) *OverflowBetaClient_FillUpStorage_Call { +func (_c *OverflowBetaClient_FlixScriptFileNameFN_Call) RunAndReturn(run func(string, ...overflow.OverflowInteractionOption) overflow.OverflowScriptOptsFunction) *OverflowBetaClient_FlixScriptFileNameFN_Call { + _c.Call.Return(run) + return _c +} + +// FlixTx provides a mock function with given fields: filename, opts +func (_m *OverflowBetaClient) FlixTx(filename string, opts ...overflow.OverflowInteractionOption) *overflow.OverflowResult { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, filename) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FlixTx") + } + + var r0 *overflow.OverflowResult + if rf, ok := ret.Get(0).(func(string, ...overflow.OverflowInteractionOption) *overflow.OverflowResult); ok { + r0 = rf(filename, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*overflow.OverflowResult) + } + } + + return r0 +} + +// OverflowBetaClient_FlixTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixTx' +type OverflowBetaClient_FlixTx_Call struct { + *mock.Call +} + +// FlixTx is a helper method to define mock.On call +// - filename string +// - opts ...overflow.OverflowInteractionOption +func (_e *OverflowBetaClient_Expecter) FlixTx(filename interface{}, opts ...interface{}) *OverflowBetaClient_FlixTx_Call { + return &OverflowBetaClient_FlixTx_Call{Call: _e.mock.On("FlixTx", + append([]interface{}{filename}, opts...)...)} +} + +func (_c *OverflowBetaClient_FlixTx_Call) Run(run func(filename string, opts ...overflow.OverflowInteractionOption)) *OverflowBetaClient_FlixTx_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *OverflowBetaClient_FlixTx_Call) Return(_a0 *overflow.OverflowResult) *OverflowBetaClient_FlixTx_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowBetaClient_FlixTx_Call) RunAndReturn(run func(string, ...overflow.OverflowInteractionOption) *overflow.OverflowResult) *OverflowBetaClient_FlixTx_Call { + _c.Call.Return(run) + return _c +} + +// FlixTxFN provides a mock function with given fields: outerOpts +func (_m *OverflowBetaClient) FlixTxFN(outerOpts ...overflow.OverflowInteractionOption) overflow.OverflowTransactionFunction { + _va := make([]interface{}, len(outerOpts)) + for _i := range outerOpts { + _va[_i] = outerOpts[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FlixTxFN") + } + + var r0 overflow.OverflowTransactionFunction + if rf, ok := ret.Get(0).(func(...overflow.OverflowInteractionOption) overflow.OverflowTransactionFunction); ok { + r0 = rf(outerOpts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(overflow.OverflowTransactionFunction) + } + } + + return r0 +} + +// OverflowBetaClient_FlixTxFN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixTxFN' +type OverflowBetaClient_FlixTxFN_Call struct { + *mock.Call +} + +// FlixTxFN is a helper method to define mock.On call +// - outerOpts ...overflow.OverflowInteractionOption +func (_e *OverflowBetaClient_Expecter) FlixTxFN(outerOpts ...interface{}) *OverflowBetaClient_FlixTxFN_Call { + return &OverflowBetaClient_FlixTxFN_Call{Call: _e.mock.On("FlixTxFN", + append([]interface{}{}, outerOpts...)...)} +} + +func (_c *OverflowBetaClient_FlixTxFN_Call) Run(run func(outerOpts ...overflow.OverflowInteractionOption)) *OverflowBetaClient_FlixTxFN_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *OverflowBetaClient_FlixTxFN_Call) Return(_a0 overflow.OverflowTransactionFunction) *OverflowBetaClient_FlixTxFN_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowBetaClient_FlixTxFN_Call) RunAndReturn(run func(...overflow.OverflowInteractionOption) overflow.OverflowTransactionFunction) *OverflowBetaClient_FlixTxFN_Call { + _c.Call.Return(run) + return _c +} + +// FlixTxFileNameFN provides a mock function with given fields: filename, outerOpts +func (_m *OverflowBetaClient) FlixTxFileNameFN(filename string, outerOpts ...overflow.OverflowInteractionOption) overflow.OverflowTransactionOptsFunction { + _va := make([]interface{}, len(outerOpts)) + for _i := range outerOpts { + _va[_i] = outerOpts[_i] + } + var _ca []interface{} + _ca = append(_ca, filename) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FlixTxFileNameFN") + } + + var r0 overflow.OverflowTransactionOptsFunction + if rf, ok := ret.Get(0).(func(string, ...overflow.OverflowInteractionOption) overflow.OverflowTransactionOptsFunction); ok { + r0 = rf(filename, outerOpts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(overflow.OverflowTransactionOptsFunction) + } + } + + return r0 +} + +// OverflowBetaClient_FlixTxFileNameFN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixTxFileNameFN' +type OverflowBetaClient_FlixTxFileNameFN_Call struct { + *mock.Call +} + +// FlixTxFileNameFN is a helper method to define mock.On call +// - filename string +// - outerOpts ...overflow.OverflowInteractionOption +func (_e *OverflowBetaClient_Expecter) FlixTxFileNameFN(filename interface{}, outerOpts ...interface{}) *OverflowBetaClient_FlixTxFileNameFN_Call { + return &OverflowBetaClient_FlixTxFileNameFN_Call{Call: _e.mock.On("FlixTxFileNameFN", + append([]interface{}{filename}, outerOpts...)...)} +} + +func (_c *OverflowBetaClient_FlixTxFileNameFN_Call) Run(run func(filename string, outerOpts ...overflow.OverflowInteractionOption)) *OverflowBetaClient_FlixTxFileNameFN_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *OverflowBetaClient_FlixTxFileNameFN_Call) Return(_a0 overflow.OverflowTransactionOptsFunction) *OverflowBetaClient_FlixTxFileNameFN_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowBetaClient_FlixTxFileNameFN_Call) RunAndReturn(run func(string, ...overflow.OverflowInteractionOption) overflow.OverflowTransactionOptsFunction) *OverflowBetaClient_FlixTxFileNameFN_Call { _c.Call.Return(run) return _c } diff --git a/mocks/OverflowClient.go b/mocks/OverflowClient.go index bfc7852..74c03f4 100644 --- a/mocks/OverflowClient.go +++ b/mocks/OverflowClient.go @@ -381,48 +381,161 @@ func (_c *OverflowClient_DownloadImageAndUploadAsDataUrl_Call) RunAndReturn(run return _c } -// FetchEventsWithResult provides a mock function with given fields: opts -func (_m *OverflowClient) FetchEventsWithResult(opts ...overflow.OverflowEventFetcherOption) overflow.EventFetcherResult { +// FillUpStorage provides a mock function with given fields: accountName +func (_m *OverflowClient) FillUpStorage(accountName string) *overflow.OverflowState { + ret := _m.Called(accountName) + + if len(ret) == 0 { + panic("no return value specified for FillUpStorage") + } + + var r0 *overflow.OverflowState + if rf, ok := ret.Get(0).(func(string) *overflow.OverflowState); ok { + r0 = rf(accountName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*overflow.OverflowState) + } + } + + return r0 +} + +// OverflowClient_FillUpStorage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FillUpStorage' +type OverflowClient_FillUpStorage_Call struct { + *mock.Call +} + +// FillUpStorage is a helper method to define mock.On call +// - accountName string +func (_e *OverflowClient_Expecter) FillUpStorage(accountName interface{}) *OverflowClient_FillUpStorage_Call { + return &OverflowClient_FillUpStorage_Call{Call: _e.mock.On("FillUpStorage", accountName)} +} + +func (_c *OverflowClient_FillUpStorage_Call) Run(run func(accountName string)) *OverflowClient_FillUpStorage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *OverflowClient_FillUpStorage_Call) Return(_a0 *overflow.OverflowState) *OverflowClient_FillUpStorage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowClient_FillUpStorage_Call) RunAndReturn(run func(string) *overflow.OverflowState) *OverflowClient_FillUpStorage_Call { + _c.Call.Return(run) + return _c +} + +// FlixScript provides a mock function with given fields: filename, opts +func (_m *OverflowClient) FlixScript(filename string, opts ...overflow.OverflowInteractionOption) *overflow.OverflowScriptResult { _va := make([]interface{}, len(opts)) for _i := range opts { _va[_i] = opts[_i] } var _ca []interface{} + _ca = append(_ca, filename) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FlixScript") + } + + var r0 *overflow.OverflowScriptResult + if rf, ok := ret.Get(0).(func(string, ...overflow.OverflowInteractionOption) *overflow.OverflowScriptResult); ok { + r0 = rf(filename, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*overflow.OverflowScriptResult) + } + } + + return r0 +} + +// OverflowClient_FlixScript_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixScript' +type OverflowClient_FlixScript_Call struct { + *mock.Call +} + +// FlixScript is a helper method to define mock.On call +// - filename string +// - opts ...overflow.OverflowInteractionOption +func (_e *OverflowClient_Expecter) FlixScript(filename interface{}, opts ...interface{}) *OverflowClient_FlixScript_Call { + return &OverflowClient_FlixScript_Call{Call: _e.mock.On("FlixScript", + append([]interface{}{filename}, opts...)...)} +} + +func (_c *OverflowClient_FlixScript_Call) Run(run func(filename string, opts ...overflow.OverflowInteractionOption)) *OverflowClient_FlixScript_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *OverflowClient_FlixScript_Call) Return(_a0 *overflow.OverflowScriptResult) *OverflowClient_FlixScript_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowClient_FlixScript_Call) RunAndReturn(run func(string, ...overflow.OverflowInteractionOption) *overflow.OverflowScriptResult) *OverflowClient_FlixScript_Call { + _c.Call.Return(run) + return _c +} + +// FlixScriptFN provides a mock function with given fields: outerOpts +func (_m *OverflowClient) FlixScriptFN(outerOpts ...overflow.OverflowInteractionOption) overflow.OverflowScriptFunction { + _va := make([]interface{}, len(outerOpts)) + for _i := range outerOpts { + _va[_i] = outerOpts[_i] + } + var _ca []interface{} _ca = append(_ca, _va...) ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for FetchEventsWithResult") + panic("no return value specified for FlixScriptFN") } - var r0 overflow.EventFetcherResult - if rf, ok := ret.Get(0).(func(...overflow.OverflowEventFetcherOption) overflow.EventFetcherResult); ok { - r0 = rf(opts...) + var r0 overflow.OverflowScriptFunction + if rf, ok := ret.Get(0).(func(...overflow.OverflowInteractionOption) overflow.OverflowScriptFunction); ok { + r0 = rf(outerOpts...) } else { - r0 = ret.Get(0).(overflow.EventFetcherResult) + if ret.Get(0) != nil { + r0 = ret.Get(0).(overflow.OverflowScriptFunction) + } } return r0 } -// OverflowClient_FetchEventsWithResult_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FetchEventsWithResult' -type OverflowClient_FetchEventsWithResult_Call struct { +// OverflowClient_FlixScriptFN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixScriptFN' +type OverflowClient_FlixScriptFN_Call struct { *mock.Call } -// FetchEventsWithResult is a helper method to define mock.On call -// - opts ...overflow.OverflowEventFetcherOption -func (_e *OverflowClient_Expecter) FetchEventsWithResult(opts ...interface{}) *OverflowClient_FetchEventsWithResult_Call { - return &OverflowClient_FetchEventsWithResult_Call{Call: _e.mock.On("FetchEventsWithResult", - append([]interface{}{}, opts...)...)} +// FlixScriptFN is a helper method to define mock.On call +// - outerOpts ...overflow.OverflowInteractionOption +func (_e *OverflowClient_Expecter) FlixScriptFN(outerOpts ...interface{}) *OverflowClient_FlixScriptFN_Call { + return &OverflowClient_FlixScriptFN_Call{Call: _e.mock.On("FlixScriptFN", + append([]interface{}{}, outerOpts...)...)} } -func (_c *OverflowClient_FetchEventsWithResult_Call) Run(run func(opts ...overflow.OverflowEventFetcherOption)) *OverflowClient_FetchEventsWithResult_Call { +func (_c *OverflowClient_FlixScriptFN_Call) Run(run func(outerOpts ...overflow.OverflowInteractionOption)) *OverflowClient_FlixScriptFN_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]overflow.OverflowEventFetcherOption, len(args)-0) + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-0) for i, a := range args[0:] { if a != nil { - variadicArgs[i] = a.(overflow.OverflowEventFetcherOption) + variadicArgs[i] = a.(overflow.OverflowInteractionOption) } } run(variadicArgs...) @@ -430,60 +543,262 @@ func (_c *OverflowClient_FetchEventsWithResult_Call) Run(run func(opts ...overfl return _c } -func (_c *OverflowClient_FetchEventsWithResult_Call) Return(_a0 overflow.EventFetcherResult) *OverflowClient_FetchEventsWithResult_Call { +func (_c *OverflowClient_FlixScriptFN_Call) Return(_a0 overflow.OverflowScriptFunction) *OverflowClient_FlixScriptFN_Call { _c.Call.Return(_a0) return _c } -func (_c *OverflowClient_FetchEventsWithResult_Call) RunAndReturn(run func(...overflow.OverflowEventFetcherOption) overflow.EventFetcherResult) *OverflowClient_FetchEventsWithResult_Call { +func (_c *OverflowClient_FlixScriptFN_Call) RunAndReturn(run func(...overflow.OverflowInteractionOption) overflow.OverflowScriptFunction) *OverflowClient_FlixScriptFN_Call { _c.Call.Return(run) return _c } -// FillUpStorage provides a mock function with given fields: accountName -func (_m *OverflowClient) FillUpStorage(accountName string) *overflow.OverflowState { - ret := _m.Called(accountName) +// FlixScriptFileNameFN provides a mock function with given fields: filename, outerOpts +func (_m *OverflowClient) FlixScriptFileNameFN(filename string, outerOpts ...overflow.OverflowInteractionOption) overflow.OverflowScriptOptsFunction { + _va := make([]interface{}, len(outerOpts)) + for _i := range outerOpts { + _va[_i] = outerOpts[_i] + } + var _ca []interface{} + _ca = append(_ca, filename) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for FillUpStorage") + panic("no return value specified for FlixScriptFileNameFN") } - var r0 *overflow.OverflowState - if rf, ok := ret.Get(0).(func(string) *overflow.OverflowState); ok { - r0 = rf(accountName) + var r0 overflow.OverflowScriptOptsFunction + if rf, ok := ret.Get(0).(func(string, ...overflow.OverflowInteractionOption) overflow.OverflowScriptOptsFunction); ok { + r0 = rf(filename, outerOpts...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*overflow.OverflowState) + r0 = ret.Get(0).(overflow.OverflowScriptOptsFunction) } } return r0 } -// OverflowClient_FillUpStorage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FillUpStorage' -type OverflowClient_FillUpStorage_Call struct { +// OverflowClient_FlixScriptFileNameFN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixScriptFileNameFN' +type OverflowClient_FlixScriptFileNameFN_Call struct { *mock.Call } -// FillUpStorage is a helper method to define mock.On call -// - accountName string -func (_e *OverflowClient_Expecter) FillUpStorage(accountName interface{}) *OverflowClient_FillUpStorage_Call { - return &OverflowClient_FillUpStorage_Call{Call: _e.mock.On("FillUpStorage", accountName)} +// FlixScriptFileNameFN is a helper method to define mock.On call +// - filename string +// - outerOpts ...overflow.OverflowInteractionOption +func (_e *OverflowClient_Expecter) FlixScriptFileNameFN(filename interface{}, outerOpts ...interface{}) *OverflowClient_FlixScriptFileNameFN_Call { + return &OverflowClient_FlixScriptFileNameFN_Call{Call: _e.mock.On("FlixScriptFileNameFN", + append([]interface{}{filename}, outerOpts...)...)} } -func (_c *OverflowClient_FillUpStorage_Call) Run(run func(accountName string)) *OverflowClient_FillUpStorage_Call { +func (_c *OverflowClient_FlixScriptFileNameFN_Call) Run(run func(filename string, outerOpts ...overflow.OverflowInteractionOption)) *OverflowClient_FlixScriptFileNameFN_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(args[0].(string), variadicArgs...) }) return _c } -func (_c *OverflowClient_FillUpStorage_Call) Return(_a0 *overflow.OverflowState) *OverflowClient_FillUpStorage_Call { +func (_c *OverflowClient_FlixScriptFileNameFN_Call) Return(_a0 overflow.OverflowScriptOptsFunction) *OverflowClient_FlixScriptFileNameFN_Call { _c.Call.Return(_a0) return _c } -func (_c *OverflowClient_FillUpStorage_Call) RunAndReturn(run func(string) *overflow.OverflowState) *OverflowClient_FillUpStorage_Call { +func (_c *OverflowClient_FlixScriptFileNameFN_Call) RunAndReturn(run func(string, ...overflow.OverflowInteractionOption) overflow.OverflowScriptOptsFunction) *OverflowClient_FlixScriptFileNameFN_Call { + _c.Call.Return(run) + return _c +} + +// FlixTx provides a mock function with given fields: filename, opts +func (_m *OverflowClient) FlixTx(filename string, opts ...overflow.OverflowInteractionOption) *overflow.OverflowResult { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, filename) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FlixTx") + } + + var r0 *overflow.OverflowResult + if rf, ok := ret.Get(0).(func(string, ...overflow.OverflowInteractionOption) *overflow.OverflowResult); ok { + r0 = rf(filename, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*overflow.OverflowResult) + } + } + + return r0 +} + +// OverflowClient_FlixTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixTx' +type OverflowClient_FlixTx_Call struct { + *mock.Call +} + +// FlixTx is a helper method to define mock.On call +// - filename string +// - opts ...overflow.OverflowInteractionOption +func (_e *OverflowClient_Expecter) FlixTx(filename interface{}, opts ...interface{}) *OverflowClient_FlixTx_Call { + return &OverflowClient_FlixTx_Call{Call: _e.mock.On("FlixTx", + append([]interface{}{filename}, opts...)...)} +} + +func (_c *OverflowClient_FlixTx_Call) Run(run func(filename string, opts ...overflow.OverflowInteractionOption)) *OverflowClient_FlixTx_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *OverflowClient_FlixTx_Call) Return(_a0 *overflow.OverflowResult) *OverflowClient_FlixTx_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowClient_FlixTx_Call) RunAndReturn(run func(string, ...overflow.OverflowInteractionOption) *overflow.OverflowResult) *OverflowClient_FlixTx_Call { + _c.Call.Return(run) + return _c +} + +// FlixTxFN provides a mock function with given fields: outerOpts +func (_m *OverflowClient) FlixTxFN(outerOpts ...overflow.OverflowInteractionOption) overflow.OverflowTransactionFunction { + _va := make([]interface{}, len(outerOpts)) + for _i := range outerOpts { + _va[_i] = outerOpts[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FlixTxFN") + } + + var r0 overflow.OverflowTransactionFunction + if rf, ok := ret.Get(0).(func(...overflow.OverflowInteractionOption) overflow.OverflowTransactionFunction); ok { + r0 = rf(outerOpts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(overflow.OverflowTransactionFunction) + } + } + + return r0 +} + +// OverflowClient_FlixTxFN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixTxFN' +type OverflowClient_FlixTxFN_Call struct { + *mock.Call +} + +// FlixTxFN is a helper method to define mock.On call +// - outerOpts ...overflow.OverflowInteractionOption +func (_e *OverflowClient_Expecter) FlixTxFN(outerOpts ...interface{}) *OverflowClient_FlixTxFN_Call { + return &OverflowClient_FlixTxFN_Call{Call: _e.mock.On("FlixTxFN", + append([]interface{}{}, outerOpts...)...)} +} + +func (_c *OverflowClient_FlixTxFN_Call) Run(run func(outerOpts ...overflow.OverflowInteractionOption)) *OverflowClient_FlixTxFN_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *OverflowClient_FlixTxFN_Call) Return(_a0 overflow.OverflowTransactionFunction) *OverflowClient_FlixTxFN_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowClient_FlixTxFN_Call) RunAndReturn(run func(...overflow.OverflowInteractionOption) overflow.OverflowTransactionFunction) *OverflowClient_FlixTxFN_Call { + _c.Call.Return(run) + return _c +} + +// FlixTxFileNameFN provides a mock function with given fields: filename, outerOpts +func (_m *OverflowClient) FlixTxFileNameFN(filename string, outerOpts ...overflow.OverflowInteractionOption) overflow.OverflowTransactionOptsFunction { + _va := make([]interface{}, len(outerOpts)) + for _i := range outerOpts { + _va[_i] = outerOpts[_i] + } + var _ca []interface{} + _ca = append(_ca, filename) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FlixTxFileNameFN") + } + + var r0 overflow.OverflowTransactionOptsFunction + if rf, ok := ret.Get(0).(func(string, ...overflow.OverflowInteractionOption) overflow.OverflowTransactionOptsFunction); ok { + r0 = rf(filename, outerOpts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(overflow.OverflowTransactionOptsFunction) + } + } + + return r0 +} + +// OverflowClient_FlixTxFileNameFN_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FlixTxFileNameFN' +type OverflowClient_FlixTxFileNameFN_Call struct { + *mock.Call +} + +// FlixTxFileNameFN is a helper method to define mock.On call +// - filename string +// - outerOpts ...overflow.OverflowInteractionOption +func (_e *OverflowClient_Expecter) FlixTxFileNameFN(filename interface{}, outerOpts ...interface{}) *OverflowClient_FlixTxFileNameFN_Call { + return &OverflowClient_FlixTxFileNameFN_Call{Call: _e.mock.On("FlixTxFileNameFN", + append([]interface{}{filename}, outerOpts...)...)} +} + +func (_c *OverflowClient_FlixTxFileNameFN_Call) Run(run func(filename string, outerOpts ...overflow.OverflowInteractionOption)) *OverflowClient_FlixTxFileNameFN_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]overflow.OverflowInteractionOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(overflow.OverflowInteractionOption) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *OverflowClient_FlixTxFileNameFN_Call) Return(_a0 overflow.OverflowTransactionOptsFunction) *OverflowClient_FlixTxFileNameFN_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OverflowClient_FlixTxFileNameFN_Call) RunAndReturn(run func(string, ...overflow.OverflowInteractionOption) overflow.OverflowTransactionOptsFunction) *OverflowClient_FlixTxFileNameFN_Call { _c.Call.Return(run) return _c } @@ -814,6 +1129,65 @@ func (_c *OverflowClient_GetNetwork_Call) RunAndReturn(run func() string) *Overf return _c } +// GetOverflowTransactionById provides a mock function with given fields: ctx, id +func (_m *OverflowClient) GetOverflowTransactionById(ctx context.Context, id flow.Identifier) (*overflow.OverflowTransaction, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetOverflowTransactionById") + } + + var r0 *overflow.OverflowTransaction + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, flow.Identifier) (*overflow.OverflowTransaction, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, flow.Identifier) *overflow.OverflowTransaction); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*overflow.OverflowTransaction) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, flow.Identifier) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// OverflowClient_GetOverflowTransactionById_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetOverflowTransactionById' +type OverflowClient_GetOverflowTransactionById_Call struct { + *mock.Call +} + +// GetOverflowTransactionById is a helper method to define mock.On call +// - ctx context.Context +// - id flow.Identifier +func (_e *OverflowClient_Expecter) GetOverflowTransactionById(ctx interface{}, id interface{}) *OverflowClient_GetOverflowTransactionById_Call { + return &OverflowClient_GetOverflowTransactionById_Call{Call: _e.mock.On("GetOverflowTransactionById", ctx, id)} +} + +func (_c *OverflowClient_GetOverflowTransactionById_Call) Run(run func(ctx context.Context, id flow.Identifier)) *OverflowClient_GetOverflowTransactionById_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(flow.Identifier)) + }) + return _c +} + +func (_c *OverflowClient_GetOverflowTransactionById_Call) Return(_a0 *overflow.OverflowTransaction, _a1 error) *OverflowClient_GetOverflowTransactionById_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *OverflowClient_GetOverflowTransactionById_Call) RunAndReturn(run func(context.Context, flow.Identifier) (*overflow.OverflowTransaction, error)) *OverflowClient_GetOverflowTransactionById_Call { + _c.Call.Return(run) + return _c +} + // GetTransactionById provides a mock function with given fields: ctx, id func (_m *OverflowClient) GetTransactionById(ctx context.Context, id flow.Identifier) (*flow.Transaction, error) { ret := _m.Called(ctx, id) diff --git a/state.go b/state.go index 97eb817..c46b404 100644 --- a/state.go +++ b/state.go @@ -63,7 +63,6 @@ type OverflowClient interface { GetLatestBlock(ctx context.Context) (*flow.Block, error) GetBlockAtHeight(ctx context.Context, height uint64) (*flow.Block, error) GetBlockById(ctx context.Context, blockId string) (*flow.Block, error) - FetchEventsWithResult(opts ...OverflowEventFetcherOption) EventFetcherResult UploadFile(filename string, accountName string) error DownloadAndUploadFile(url string, accountName string) error @@ -77,15 +76,6 @@ type OverflowClient interface { SignUserMessage(account string, message string) (string, error) GetTransactionById(ctx context.Context, id flow.Identifier) (*flow.Transaction, error) -} - -// beta client with unstable features -type OverflowBetaClient interface { - OverflowClient - StreamTransactions(ctx context.Context, poll time.Duration, height uint64, logger *zap.Logger, channel chan<- BlockResult) error - GetBlockResult(ctx context.Context, height uint64, logger *zap.Logger) (*BlockResult, error) - GetOverflowTransactionById(ctx context.Context, id flow.Identifier) (*OverflowTransaction, error) - GetOverflowTransactionsForBlockId(ctx context.Context, id flow.Identifier, logg *zap.Logger) ([]OverflowTransaction, OverflowEvents, error) FlixTx(filename string, opts ...OverflowInteractionOption) *OverflowResult FlixTxFN(outerOpts ...OverflowInteractionOption) OverflowTransactionFunction @@ -94,6 +84,16 @@ type OverflowBetaClient interface { FlixScriptFN(outerOpts ...OverflowInteractionOption) OverflowScriptFunction FlixScriptFileNameFN(filename string, outerOpts ...OverflowInteractionOption) OverflowScriptOptsFunction FlixScript(filename string, opts ...OverflowInteractionOption) *OverflowScriptResult + + GetOverflowTransactionById(ctx context.Context, id flow.Identifier) (*OverflowTransaction, error) +} + +// beta client with unstable features +type OverflowBetaClient interface { + OverflowClient + StreamTransactions(ctx context.Context, poll time.Duration, height uint64, logger *zap.Logger, channel chan<- BlockResult) error + GetBlockResult(ctx context.Context, height uint64, logger *zap.Logger) (*BlockResult, error) + GetOverflowTransactionsForBlockId(ctx context.Context, id flow.Identifier, logg *zap.Logger) ([]OverflowTransaction, OverflowEvents, error) } var (