-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #471 from multiversx/MX-15407-tx-notarization-checker
Tx notarization checker
- Loading branch information
Showing
14 changed files
with
169 additions
and
7 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
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
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
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,22 @@ | ||
package factory | ||
|
||
import ( | ||
"github.com/multiversx/mx-chain-core-go/data/transaction" | ||
) | ||
|
||
type sovereignTxNotarizationChecker struct{} | ||
|
||
// NewSovereignTxNotarizationChecker creates a new sovereign tx notarization checker | ||
func NewSovereignTxNotarizationChecker() *sovereignTxNotarizationChecker { | ||
return &sovereignTxNotarizationChecker{} | ||
} | ||
|
||
// IsNotarized returns true | ||
func (stnc *sovereignTxNotarizationChecker) IsNotarized(_ transaction.ApiTransactionResult) bool { | ||
return true | ||
} | ||
|
||
// IsInterfaceNil returns true if there is no value under the interface | ||
func (stnc *sovereignTxNotarizationChecker) IsInterfaceNil() bool { | ||
return stnc == nil | ||
} |
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,23 @@ | ||
package factory | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/data/transaction" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSovereignTxNotarizationChecker(t *testing.T) { | ||
t.Parallel() | ||
|
||
tnc := NewTxNotarizationChecker() | ||
require.False(t, tnc.IsInterfaceNil()) | ||
} | ||
|
||
func TestSovereignTxNotarizationChecker_IsNotarized(t *testing.T) { | ||
t.Parallel() | ||
|
||
tnc := NewTxNotarizationChecker() | ||
isNotarized := tnc.IsNotarized(transaction.ApiTransactionResult{}) | ||
require.True(t, isNotarized) | ||
} |
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,22 @@ | ||
package factory | ||
|
||
import ( | ||
"github.com/multiversx/mx-chain-core-go/data/transaction" | ||
) | ||
|
||
type txNotarizationChecker struct{} | ||
|
||
// NewTxNotarizationChecker creates a new tx notarization checker | ||
func NewTxNotarizationChecker() *txNotarizationChecker { | ||
return &txNotarizationChecker{} | ||
} | ||
|
||
// IsNotarized returns if tx is notarized | ||
func (tnc *txNotarizationChecker) IsNotarized(tx transaction.ApiTransactionResult) bool { | ||
return tx.NotarizedAtSourceInMetaNonce > 0 && tx.NotarizedAtDestinationInMetaNonce > 0 | ||
} | ||
|
||
// IsInterfaceNil returns true if there is no value under the interface | ||
func (tnc *txNotarizationChecker) IsInterfaceNil() bool { | ||
return tnc == nil | ||
} |
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,34 @@ | ||
package factory | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/data/transaction" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTxNotarizationChecker(t *testing.T) { | ||
t.Parallel() | ||
|
||
tnc := NewTxNotarizationChecker() | ||
require.False(t, tnc.IsInterfaceNil()) | ||
} | ||
|
||
func TestTxNotarizationChecker_IsNotarized(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("tx is notarized", func(t *testing.T) { | ||
tnc := NewTxNotarizationChecker() | ||
tx := transaction.ApiTransactionResult{ | ||
NotarizedAtSourceInMetaNonce: 1, | ||
NotarizedAtDestinationInMetaNonce: 1, | ||
} | ||
isNotarized := tnc.IsNotarized(tx) | ||
require.True(t, isNotarized) | ||
}) | ||
t.Run("tx is not notarized", func(t *testing.T) { | ||
tnc := NewTxNotarizationChecker() | ||
isNotarized := tnc.IsNotarized(transaction.ApiTransactionResult{}) | ||
require.False(t, isNotarized) | ||
}) | ||
} |
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