-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor:
NewMinedRelay
to shared testutil (#262)
- Loading branch information
1 parent
410965a
commit df73cfa
Showing
2 changed files
with
45 additions
and
36 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 testrelayer | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pokt-network/poktroll/pkg/relayer" | ||
"github.com/pokt-network/poktroll/pkg/relayer/miner" | ||
servicetypes "github.com/pokt-network/poktroll/x/service/types" | ||
sessiontypes "github.com/pokt-network/poktroll/x/session/types" | ||
) | ||
|
||
// NewMinedRelay returns a new mined relay with the given session start and end | ||
// heights on the session header, and the bytes and hash fields populated. | ||
func NewMinedRelay( | ||
t *testing.T, | ||
sessionStartHeight int64, | ||
sessionEndHeight int64, | ||
) *relayer.MinedRelay { | ||
relay := servicetypes.Relay{ | ||
Req: &servicetypes.RelayRequest{ | ||
Meta: &servicetypes.RelayRequestMetadata{ | ||
SessionHeader: &sessiontypes.SessionHeader{ | ||
SessionStartBlockHeight: sessionStartHeight, | ||
SessionEndBlockHeight: sessionEndHeight, | ||
}, | ||
}, | ||
}, | ||
Res: &servicetypes.RelayResponse{}, | ||
} | ||
|
||
// TODO_BLOCKER: use canonical codec to serialize the relay | ||
relayBz, err := relay.Marshal() | ||
require.NoError(t, err) | ||
|
||
relayHash := HashBytes(t, miner.DefaultRelayHasher, relayBz) | ||
|
||
return &relayer.MinedRelay{ | ||
Relay: relay, | ||
Bytes: relayBz, | ||
Hash: relayHash, | ||
} | ||
} |