7
7
"strings"
8
8
"testing"
9
9
10
+ "github.com/pkg/errors"
10
11
"github.com/rs/zerolog"
11
12
"github.com/rs/zerolog/log"
12
13
"github.com/stretchr/testify/require"
@@ -21,6 +22,8 @@ import (
21
22
zctx "github.com/zeta-chain/node/zetaclient/context"
22
23
"github.com/zeta-chain/node/zetaclient/db"
23
24
"github.com/zeta-chain/node/zetaclient/testutils/mocks"
25
+ "google.golang.org/grpc/codes"
26
+ "google.golang.org/grpc/status"
24
27
)
25
28
26
29
const (
@@ -538,9 +541,10 @@ func TestPostVoteInbound(t *testing.T) {
538
541
ob := newTestSuite (t , chains .Ethereum )
539
542
540
543
ob .zetacore .WithPostVoteInbound ("" , "sampleBallotIndex" )
541
-
542
544
// post vote inbound
543
545
msg := sample .InboundVote (coin .CoinType_Gas , chains .Ethereum .ChainId , chains .ZetaChainMainnet .ChainId )
546
+ ob .zetacore .MockGetCctxByHash (msg .Digest (), errors .New ("not found" ))
547
+
544
548
ballot , err := ob .PostVoteInbound (context .TODO (), & msg , 100000 )
545
549
require .NoError (t , err )
546
550
require .Equal (t , "sampleBallotIndex" , ballot )
@@ -553,12 +557,29 @@ func TestPostVoteInbound(t *testing.T) {
553
557
// create sample message with long Message
554
558
msg := sample .InboundVote (coin .CoinType_Gas , chains .Ethereum .ChainId , chains .ZetaChainMainnet .ChainId )
555
559
msg .Message = strings .Repeat ("1" , crosschaintypes .MaxMessageLength + 1 )
560
+ ob .zetacore .MockGetCctxByHash (msg .Digest (), errors .New ("not found" ))
556
561
557
562
// post vote inbound
558
563
ballot , err := ob .PostVoteInbound (context .TODO (), & msg , 100000 )
559
564
require .NoError (t , err )
560
565
require .Empty (t , ballot )
561
566
})
567
+
568
+ t .Run ("should not post vote cctx already exists and ballot is not found" , func (t * testing.T ) {
569
+ //Arrange
570
+ // create observer
571
+ ob := newTestSuite (t , chains .Ethereum )
572
+ // create sample message with long Message
573
+ msg := sample .InboundVote (coin .CoinType_Gas , chains .Ethereum .ChainId , chains .ZetaChainMainnet .ChainId )
574
+ msg .Message = strings .Repeat ("1" , crosschaintypes .MaxMessageLength + 1 )
575
+ ob .zetacore .MockGetCctxByHash (msg .Digest (), nil )
576
+ ob .zetacore .MockGetBallotByID (msg .Digest (), status .Error (codes .NotFound , "not found ballot" ))
577
+ // Act
578
+ ballot , err := ob .PostVoteInbound (context .TODO (), & msg , 100000 )
579
+ // Assert
580
+ require .NoError (t , err )
581
+ require .Equal (t , ballot , msg .Digest ())
582
+ })
562
583
}
563
584
564
585
func createDatabase (t * testing.T ) * db.DB {
0 commit comments