-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update
ScanBlock
function with new API calls
- Add new imports for `ton` and `zap` packages - Refactor `ScanBlock` function to use new API calls and error handling - Add unit tests for the `ScanBlock` function Signed-off-by: Sean Zheng <[email protected]>
- Loading branch information
1 parent
ecfaa9c
commit c5e2b4d
Showing
3 changed files
with
93 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package biz | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/blackhorseya/ryze/app/infra/tonx" | ||
"github.com/blackhorseya/ryze/entity/domain/block/model" | ||
"github.com/blackhorseya/ryze/pkg/contextx" | ||
"github.com/stretchr/testify/suite" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
type suiteTester struct { | ||
suite.Suite | ||
|
||
ctrl *gomock.Controller | ||
client *tonx.Client | ||
biz model.BlockServiceServer | ||
} | ||
|
||
func (s *suiteTester) SetupTest() { | ||
s.ctrl = gomock.NewController(s.T()) | ||
s.client, _ = tonx.NewClient(tonx.Options{Network: "testnet"}) | ||
s.biz = NewBlockService(s.client) | ||
} | ||
|
||
func (s *suiteTester) TearDownTest() { | ||
s.ctrl.Finish() | ||
} | ||
|
||
func TestAll(t *testing.T) { | ||
suite.Run(t, new(suiteTester)) | ||
} | ||
|
||
func (s *suiteTester) Test_impl_ScanBlock() { | ||
stream := model.NewMockBlockService_ScanBlockServer(s.ctrl) | ||
|
||
timeout, cancelFunc := contextx.WithTimeout(contextx.Background(), 2*time.Second) | ||
defer cancelFunc() | ||
|
||
stream.EXPECT().Context().Return(timeout).Times(1) | ||
_ = s.biz.ScanBlock(&model.ScanBlockRequest{}, stream) | ||
} |
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,12 @@ | ||
package tonx | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/xssnick/tonutils-go/ton" | ||
) | ||
|
||
// GetShardID is used to get the shard id | ||
func GetShardID(shard *ton.BlockIDExt) string { | ||
return fmt.Sprintf("%d|%d", shard.Workchain, shard.Shard) | ||
} |