-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d570e95
commit d060cb9
Showing
7 changed files
with
170 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package restore | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gnolang/gno/tm2/pkg/std" | ||
) | ||
|
||
type ( | ||
sendTransactionDelegate func(*std.Tx) error | ||
) | ||
|
||
type mockClient struct { | ||
sendTransactionFn sendTransactionDelegate | ||
} | ||
|
||
func (m *mockClient) SendTransaction(tx *std.Tx) error { | ||
if m.sendTransactionFn != nil { | ||
return m.sendTransactionFn(tx) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type ( | ||
nextDelegate func(context.Context) (*std.Tx, error) | ||
closeDelegate func() error | ||
) | ||
|
||
type mockSource struct { | ||
nextFn nextDelegate | ||
closeFn closeDelegate | ||
} | ||
|
||
func (m *mockSource) Next(ctx context.Context) (*std.Tx, error) { | ||
if m.nextFn != nil { | ||
return m.nextFn(ctx) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func (m *mockSource) Close() error { | ||
if m.closeFn != nil { | ||
return m.closeFn() | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package restore | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"testing" | ||
|
||
"github.com/gnolang/gno/tm2/pkg/std" | ||
"github.com/gnolang/tx-archive/log/noop" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRestore_ExecuteRestore(t *testing.T) { | ||
t.Parallel() | ||
|
||
var ( | ||
exampleTxCount = 10 | ||
exampleTxGiven = 0 | ||
|
||
exampleTx = &std.Tx{ | ||
Memo: "example tx", | ||
} | ||
|
||
sentTxs = make([]*std.Tx, 0) | ||
|
||
mockClient = &mockClient{ | ||
sendTransactionFn: func(tx *std.Tx) error { | ||
sentTxs = append(sentTxs, tx) | ||
|
||
return nil | ||
}, | ||
} | ||
mockSource = &mockSource{ | ||
nextFn: func(ctx context.Context) (*std.Tx, error) { | ||
if exampleTxGiven == exampleTxCount { | ||
return nil, io.EOF | ||
} | ||
|
||
exampleTxGiven++ | ||
|
||
return exampleTx, nil | ||
}, | ||
} | ||
) | ||
|
||
// Execute the restore | ||
assert.NoError( | ||
t, | ||
ExecuteRestore( | ||
context.Background(), | ||
mockClient, | ||
mockSource, | ||
noop.New(), | ||
), | ||
) | ||
|
||
// Verify the restore was correct | ||
assert.Len(t, sentTxs, exampleTxCount) | ||
|
||
for _, tx := range sentTxs { | ||
assert.Equal(t, exampleTx, tx) | ||
} | ||
} |