@@ -727,77 +727,71 @@ func TestLocalLiquidityProvider_StateConfiguration(t *testing.T) {
727727 btcUnix := time .Date (2024 , 1 , 15 , 10 , 30 , 0 , 0 , time .UTC ).Unix ()
728728 rbtcUnix := time .Date (2024 , 1 , 20 , 14 , 45 , 0 , 0 , time .UTC ).Unix ()
729729 stateConfigValue := liquidity_provider.StateConfiguration {
730- LastBtcToColdWalletTransfer : & btcUnix ,
731- LastRbtcToColdWalletTransfer : & rbtcUnix ,
730+ LastBtcToColdWalletTransfer : btcUnix ,
731+ LastRbtcToColdWalletTransfer : rbtcUnix ,
732732 }
733733
734734 signedConfig , err := usecases .SignConfiguration (usecases .InitializeStateConfigurationId , wallet , crypto .Keccak256 , stateConfigValue )
735735 require .NoError (t , err )
736736
737737 lpRepository .On ("GetStateConfiguration" , test .AnyCtx ).Return (& signedConfig , nil ).Once ()
738738 lp := dataproviders .NewLocalLiquidityProvider (nil , nil , lpRepository , blockchain.Rpc {}, wallet , nil , blockchain.RskContracts {})
739- result := lp .StateConfiguration (context .Background ())
739+ result , err := lp .StateConfiguration (context .Background ())
740740
741+ require .NoError (t , err )
741742 assert .Equal (t , stateConfigValue , result )
742- assert .NotNil (t , result .LastBtcToColdWalletTransfer )
743- assert .NotNil (t , result .LastRbtcToColdWalletTransfer )
743+ assert .NotZero (t , result .LastBtcToColdWalletTransfer )
744+ assert .NotZero (t , result .LastRbtcToColdWalletTransfer )
744745 })
745746
746- t .Run ("Return empty state configuration when db doesn't have configuration" , func (t * testing.T ) {
747+ t .Run ("Return error when db doesn't have configuration" , func (t * testing.T ) {
747748 lpRepository .On ("GetStateConfiguration" , test .AnyCtx ).Return (nil , nil ).Once ()
748749 lp := dataproviders .NewLocalLiquidityProvider (nil , nil , lpRepository , blockchain.Rpc {}, nil , nil , blockchain.RskContracts {})
749750
750- defer test .AssertLogContains (t , "Custom state configuration not found. Using default configuration." )()
751-
752- config := lp .StateConfiguration (context .Background ())
751+ _ , err := lp .StateConfiguration (context .Background ())
753752
754- // StateConfiguration has no defaults - returns empty struct
755- assert .Nil (t , config .LastBtcToColdWalletTransfer )
756- assert .Nil (t , config .LastRbtcToColdWalletTransfer )
753+ require .ErrorIs (t , err , liquidity_provider .ConfigurationNotFoundError )
757754 })
758755
759- t .Run ("Return empty state configuration on db read error" , func (t * testing.T ) {
756+ t .Run ("Return error on db read error" , func (t * testing.T ) {
760757 lpRepository .On ("GetStateConfiguration" , test .AnyCtx ).Return (nil , errors .New ("database error" )).Once ()
761758 lp := dataproviders .NewLocalLiquidityProvider (nil , nil , lpRepository , blockchain.Rpc {}, nil , nil , blockchain.RskContracts {})
762759
763- defer test .AssertLogContains (t , "Error getting state configuration, using default configuration. Error: database error" )()
764- config := lp .StateConfiguration (context .Background ())
760+ _ , err := lp .StateConfiguration (context .Background ())
765761
766- assert . Nil (t , config . LastBtcToColdWalletTransfer )
767- assert .Nil (t , config . LastRbtcToColdWalletTransfer )
762+ require . Error (t , err )
763+ assert .Contains (t , err . Error (), "database error" )
768764 })
769765
770- t .Run ("Return empty state configuration when db configuration is tampered" , func (t * testing.T ) {
766+ t .Run ("Return error when db configuration is tampered" , func (t * testing.T ) {
771767 btcUnix := time .Date (2024 , 1 , 15 , 10 , 30 , 0 , 0 , time .UTC ).Unix ()
772768 rbtcUnix := time .Date (2024 , 1 , 20 , 14 , 45 , 0 , 0 , time .UTC ).Unix ()
773769 stateConfigValue := liquidity_provider.StateConfiguration {
774- LastBtcToColdWalletTransfer : & btcUnix ,
775- LastRbtcToColdWalletTransfer : & rbtcUnix ,
770+ LastBtcToColdWalletTransfer : btcUnix ,
771+ LastRbtcToColdWalletTransfer : rbtcUnix ,
776772 }
777773
778774 tamperedConfig , err := usecases .SignConfiguration (usecases .InitializeStateConfigurationId , wallet , crypto .Keccak256 , stateConfigValue )
779775 require .NoError (t , err )
780776
781777 // Tamper with the data after signing
782778 newUnix := time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).Unix ()
783- tamperedConfig .Value .LastBtcToColdWalletTransfer = & newUnix
779+ tamperedConfig .Value .LastBtcToColdWalletTransfer = newUnix
784780
785781 lpRepository .On ("GetStateConfiguration" , test .AnyCtx ).Return (& tamperedConfig , nil ).Once ()
786782 lp := dataproviders .NewLocalLiquidityProvider (nil , nil , lpRepository , blockchain.Rpc {}, wallet , nil , blockchain.RskContracts {})
787783
788- defer test .AssertLogContains (t , "Tampered state configuration. Using default configuration." )()
789- result := lp .StateConfiguration (context .Background ())
784+ _ , err = lp .StateConfiguration (context .Background ())
790785
791- assert .Nil (t , result .LastBtcToColdWalletTransfer )
792- assert .Nil (t , result .LastRbtcToColdWalletTransfer )
786+ require .ErrorIs (t , err , entities .IntegrityError )
793787 })
794788
795- t .Run ("Return empty state configuration when db configuration doesn't have valid signature" , func (t * testing.T ) {
789+ t .Run ("Return error when db configuration doesn't have valid signature" , func (t * testing.T ) {
796790 btcUnix := time .Date (2024 , 1 , 15 , 10 , 30 , 0 , 0 , time .UTC ).Unix ()
797791 rbtcUnix := time .Date (2024 , 1 , 20 , 14 , 45 , 0 , 0 , time .UTC ).Unix ()
798792 stateConfigValue := liquidity_provider.StateConfiguration {
799- LastBtcToColdWalletTransfer : & btcUnix ,
800- LastRbtcToColdWalletTransfer : & rbtcUnix ,
793+ LastBtcToColdWalletTransfer : btcUnix ,
794+ LastRbtcToColdWalletTransfer : rbtcUnix ,
801795 }
802796
803797 // Create config with correct hash but wrong signature
@@ -809,20 +803,17 @@ func TestLocalLiquidityProvider_StateConfiguration(t *testing.T) {
809803 lpRepository .On ("GetStateConfiguration" , test .AnyCtx ).Return (& signedConfig , nil ).Once ()
810804 lp := dataproviders .NewLocalLiquidityProvider (nil , nil , lpRepository , blockchain.Rpc {}, wallet , nil , blockchain.RskContracts {})
811805
812- defer test .AssertLogContains (t , "Invalid state configuration signature. Using default configuration." )()
813-
814- result := lp .StateConfiguration (context .Background ())
806+ _ , err = lp .StateConfiguration (context .Background ())
815807
816- assert .Nil (t , result .LastBtcToColdWalletTransfer )
817- assert .Nil (t , result .LastRbtcToColdWalletTransfer )
808+ require .ErrorIs (t , err , liquidity_provider .InvalidSignatureError )
818809 })
819810
820- t .Run ("Return empty state configuration when integrity check fails" , func (t * testing.T ) {
811+ t .Run ("Return error when integrity check fails" , func (t * testing.T ) {
821812 btcUnix := time .Date (2024 , 1 , 15 , 10 , 30 , 0 , 0 , time .UTC ).Unix ()
822813 rbtcUnix := time .Date (2024 , 1 , 20 , 14 , 45 , 0 , 0 , time .UTC ).Unix ()
823814 stateConfigValue := liquidity_provider.StateConfiguration {
824- LastBtcToColdWalletTransfer : & btcUnix ,
825- LastRbtcToColdWalletTransfer : & rbtcUnix ,
815+ LastBtcToColdWalletTransfer : btcUnix ,
816+ LastRbtcToColdWalletTransfer : rbtcUnix ,
826817 }
827818
828819 integrityFailConfig , err := usecases .SignConfiguration (usecases .InitializeStateConfigurationId , wallet , crypto .Keccak256 , stateConfigValue )
@@ -834,20 +825,17 @@ func TestLocalLiquidityProvider_StateConfiguration(t *testing.T) {
834825 lpRepository .On ("GetStateConfiguration" , test .AnyCtx ).Return (& integrityFailConfig , nil ).Once ()
835826 lp := dataproviders .NewLocalLiquidityProvider (nil , nil , lpRepository , blockchain.Rpc {}, wallet , nil , blockchain.RskContracts {})
836827
837- defer test . AssertLogContains ( t , "Tampered state configuration. Using default configuration." )( )
828+ _ , err = lp . StateConfiguration ( context . Background () )
838829
839- result := lp .StateConfiguration (context .Background ())
840-
841- assert .Nil (t , result .LastBtcToColdWalletTransfer )
842- assert .Nil (t , result .LastRbtcToColdWalletTransfer )
830+ require .ErrorIs (t , err , entities .IntegrityError )
843831 })
844832
845- t .Run ("Return empty state configuration when there is an unexpected error" , func (t * testing.T ) {
833+ t .Run ("Return error when there is an unexpected error" , func (t * testing.T ) {
846834 btcUnix := time .Date (2024 , 1 , 15 , 10 , 30 , 0 , 0 , time .UTC ).Unix ()
847835 rbtcUnix := time .Date (2024 , 1 , 20 , 14 , 45 , 0 , 0 , time .UTC ).Unix ()
848836 stateConfigValue := liquidity_provider.StateConfiguration {
849- LastBtcToColdWalletTransfer : & btcUnix ,
850- LastRbtcToColdWalletTransfer : & rbtcUnix ,
837+ LastBtcToColdWalletTransfer : btcUnix ,
838+ LastRbtcToColdWalletTransfer : rbtcUnix ,
851839 }
852840
853841 integrityFailConfig , err := usecases .SignConfiguration (usecases .InitializeStateConfigurationId , wallet , crypto .Keccak256 , stateConfigValue )
@@ -859,11 +847,9 @@ func TestLocalLiquidityProvider_StateConfiguration(t *testing.T) {
859847 lpRepository .On ("GetStateConfiguration" , test .AnyCtx ).Return (& integrityFailConfig , nil ).Once ()
860848 lp := dataproviders .NewLocalLiquidityProvider (nil , nil , lpRepository , blockchain.Rpc {}, wallet , nil , blockchain.RskContracts {})
861849
862- defer test .AssertLogContains (t , "Error getting state configuration, using default configuration. Error: encoding/hex: invalid byte: U+006E" )()
863-
864- result := lp .StateConfiguration (context .Background ())
850+ _ , err = lp .StateConfiguration (context .Background ())
865851
866- assert . Nil (t , result . LastBtcToColdWalletTransfer )
867- assert .Nil (t , result . LastRbtcToColdWalletTransfer )
852+ require . Error (t , err )
853+ assert .Contains (t , err . Error (), "encoding/hex: invalid byte" )
868854 })
869855}
0 commit comments