Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashk767 committed Sep 1, 2022
1 parent 4f4ae98 commit de74a3a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 55 deletions.
19 changes: 5 additions & 14 deletions cmd/mocks/utils_cmd_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions cmd/mocks/utils_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 2 additions & 24 deletions cmd/propose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/mock"
"math/big"
"razor/cmd/mocks"
"razor/core"
"razor/core/types"
"razor/pkg/bindings"
"razor/utils"
Expand Down Expand Up @@ -84,7 +83,6 @@ func TestPropose(t *testing.T) {
tests := []struct {
name string
args args
want common.Hash
wantErr error
}{
{
Expand All @@ -106,7 +104,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: common.BigToHash(big.NewInt(1)),
wantErr: nil,
},
{
Expand All @@ -128,7 +125,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("state error"),
},
{
Expand All @@ -150,7 +146,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("numberOfStakers error"),
},
{
Expand All @@ -171,7 +166,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("biggest staker error"),
},
{
Expand All @@ -193,7 +187,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("salt error"),
},
{
Expand All @@ -215,7 +208,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: nil,
},
{
Expand All @@ -237,7 +229,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("numOfProposedBlocks error"),
},
{
Expand All @@ -259,7 +250,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("maxAltBlocks error"),
},
{
Expand All @@ -281,7 +271,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("lastProposedBlockStruct error"),
},
{
Expand All @@ -305,7 +294,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: nil,
},
{
Expand All @@ -329,7 +317,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: common.BigToHash(big.NewInt(1)),
wantErr: nil,
},
{
Expand All @@ -351,7 +338,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("makeBlock error"),
},
{
Expand All @@ -373,7 +359,6 @@ func TestPropose(t *testing.T) {
proposeErr: errors.New("propose error"),
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("propose error"),
},
{
Expand All @@ -395,7 +380,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
fileNameErr: errors.New("fileName error"),
},
want: core.NilHash,
wantErr: nil,
},
{
Expand All @@ -417,7 +401,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
saveDataErr: errors.New("error in saving data"),
},
want: core.NilHash,
wantErr: nil,
},
{
Expand All @@ -430,7 +413,6 @@ func TestPropose(t *testing.T) {
biggestStakerId: 2,
bufferPercentErr: errors.New("buffer error"),
},
want: core.NilHash,
wantErr: errors.New("buffer error"),
},
{
Expand Down Expand Up @@ -458,7 +440,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: common.BigToHash(big.NewInt(1)),
wantErr: nil,
},
{
Expand All @@ -485,7 +466,6 @@ func TestPropose(t *testing.T) {
proposeTxn: &Types.Transaction{},
hash: common.BigToHash(big.NewInt(1)),
},
want: core.NilHash,
wantErr: errors.New("smallestStakerId error"),
},
}
Expand Down Expand Up @@ -521,13 +501,11 @@ func TestPropose(t *testing.T) {
blockManagerUtilsMock.On("Propose", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tt.args.proposeTxn, tt.args.proposeErr)
transactionUtilsMock.On("Hash", mock.Anything).Return(tt.args.hash)
cmdUtilsMock.On("GetBufferPercent").Return(tt.args.bufferPercent, tt.args.bufferPercentErr)
utilsMock.On("WaitForBlockCompletion", mock.AnythingOfType("*ethclient.Client"), mock.AnythingOfType("string")).Return(nil)

utils := &UtilsStruct{}
t.Run(tt.name, func(t *testing.T) {
got, err := utils.Propose(client, config, account, staker, epoch, blockNumber, tt.args.rogueData)
if got != tt.want {
t.Errorf("Txn hash for Propose function, got = %v, want %v", got, tt.want)
}
err := utils.Propose(client, config, account, staker, epoch, blockNumber, tt.args.rogueData)
if err == nil || tt.wantErr == nil {
if err != tt.wantErr {
t.Errorf("Error for Propose function, got = %v, want %v", err, tt.wantErr)
Expand Down
5 changes: 1 addition & 4 deletions cmd/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,6 @@ func TestInitiatePropose(t *testing.T) {
lastProposalErr error
lastReveal uint32
lastRevealErr error
proposeTxn common.Hash
proposeTxnErr error
}
tests := []struct {
Expand All @@ -947,7 +946,6 @@ func TestInitiatePropose(t *testing.T) {
epoch: 5,
lastProposal: 4,
lastReveal: 6,
proposeTxn: common.BigToHash(big.NewInt(1)),
},
wantErr: false,
},
Expand All @@ -967,7 +965,6 @@ func TestInitiatePropose(t *testing.T) {
epoch: 5,
lastProposal: 4,
lastReveal: 6,
proposeTxn: common.BigToHash(big.NewInt(1)),
},
wantErr: false,
},
Expand Down Expand Up @@ -1029,7 +1026,7 @@ func TestInitiatePropose(t *testing.T) {
utilsPkgMock.On("GetMinStakeAmount", mock.AnythingOfType("*ethclient.Client")).Return(tt.args.minStakeAmount, tt.args.minStakeAmountErr)
cmdUtilsMock.On("GetLastProposedEpoch", mock.AnythingOfType("*ethclient.Client"), mock.AnythingOfType("*big.Int"), mock.AnythingOfType("uint32")).Return(tt.args.lastProposal, tt.args.lastProposalErr)
utilsMock.On("GetEpochLastRevealed", mock.AnythingOfType("*ethclient.Client"), mock.AnythingOfType("uint32")).Return(tt.args.lastReveal, tt.args.lastRevealErr)
cmdUtilsMock.On("Propose", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tt.args.proposeTxn, tt.args.proposeTxnErr)
cmdUtilsMock.On("Propose", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tt.args.proposeTxnErr)
utilsMock.On("WaitForBlockCompletion", mock.AnythingOfType("*ethclient.Client"), mock.AnythingOfType("string")).Return(nil)
ut := &UtilsStruct{}
if err := ut.InitiatePropose(client, config, account, tt.args.epoch, tt.args.staker, blockNumber, rogueData); (err != nil) != tt.wantErr {
Expand Down
5 changes: 2 additions & 3 deletions utils/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,7 @@ func TestSaveDataToCommitJsonFile(t *testing.T) {
func TestSaveDataToProposeJsonFile(t *testing.T) {
var (
filePath string
epoch uint32
proposeData Types.ProposeData
proposeData Types.ProposeFileData
)

type args struct {
Expand Down Expand Up @@ -1157,7 +1156,7 @@ func TestSaveDataToProposeJsonFile(t *testing.T) {

jsonMock.On("Marshal", mock.Anything).Return(tt.args.jsonData, tt.args.jsonDataErr)
osMock.On("WriteFile", mock.Anything, mock.Anything, mock.Anything).Return(tt.args.writeFileErr)
if err := utils.SaveDataToProposeJsonFile(filePath, epoch, proposeData); (err != nil) != tt.wantErr {
if err := utils.SaveDataToProposeJsonFile(filePath, proposeData); (err != nil) != tt.wantErr {
t.Errorf("SaveDataToProposeJsonFile() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
10 changes: 5 additions & 5 deletions utils/mocks/utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de74a3a

Please sign in to comment.