Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions overflow/blocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package overflow

import (
"fmt"

"github.com/onflow/flow-go-sdk"
)

func (f *Overflow) GetLatestBlock() (*flow.Block, error) {
block, _, _, err := f.Services.Blocks.GetBlock("latest", "", false)
return block, err
}

func (f *Overflow) GetBlockAtHeight(height uint64) (*flow.Block, error) {
block, _, _, err := f.Services.Blocks.GetBlock(fmt.Sprintf("%d", height), "", false)
return block, err
}

// blockId should be a hexadecimal string
func (f *Overflow) GetBlockById(blockId string) (*flow.Block, error) {
block, _, _, err := f.Services.Blocks.GetBlock(blockId, "", false)
return block, err
}
36 changes: 36 additions & 0 deletions overflow/blocks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package overflow

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetBlock(t *testing.T) {

t.Run("Should get latest block", func(t *testing.T) {
g, _ := NewTestingEmulator().StartE()
block, err := g.GetLatestBlock()

assert.Nil(t, err)
assert.Equal(t, uint64(0), block.Height)
})

t.Run("Should get block by height", func(t *testing.T) {
g, _ := NewTestingEmulator().StartE()
block, err := g.GetBlockAtHeight(0)

assert.Nil(t, err)
assert.Equal(t, uint64(0), block.Height)
})

t.Run("Should get block by ID", func(t *testing.T) {
BlockZeroID := "7bc42fe85d32ca513769a74f97f7e1a7bad6c9407f0d934c2aa645ef9cf613c7"
g, _ := NewTestingEmulator().StartE()
block, err := g.GetBlockById(BlockZeroID)

assert.Nil(t, err)
assert.Equal(t, BlockZeroID, block.ID.String())
})

}