diff --git a/lib/config.go b/lib/config.go index d5db083..3c8b85d 100644 --- a/lib/config.go +++ b/lib/config.go @@ -24,6 +24,7 @@ var ( libConfig *Config sdkConfig *sdk.Config initConfig sync.Once + changeLock sync.Mutex ) // DefaultConfig returns library default configuration. @@ -42,6 +43,8 @@ func DefaultConfig() *Config { // GetConfig returns the config instance for the SDK. func GetConfig() *Config { initConfig.Do(func() { + changeLock.Lock() + defer changeLock.Unlock() libConfig = DefaultConfig() sdkConfig = sdk.GetConfig() libConfig.SetBech32PrefixForAccount("plmnt") @@ -54,48 +57,64 @@ func GetConfig() *Config { // SetBech32PrefixForAccount sets the bech32 account prefix. func (config *Config) SetBech32PrefixForAccount(bech32Prefix string) *Config { + changeLock.Lock() + defer changeLock.Unlock() sdkConfig.SetBech32PrefixForAccount(bech32Prefix, "pub") return config } // SetEncodingConfig sets the encoding config and must not be nil. func (config *Config) SetEncodingConfig(encodingConfig params.EncodingConfig) *Config { + changeLock.Lock() + defer changeLock.Unlock() config.EncodingConfig = encodingConfig return config } // SetChainID sets the chain ID parameter. func (config *Config) SetChainID(chainID string) *Config { + changeLock.Lock() + defer changeLock.Unlock() config.ChainID = chainID return config } // SetClientCtx sets the client context parameter. func (config *Config) SetClientCtx(clientCtx client.Context) *Config { + changeLock.Lock() + defer changeLock.Unlock() config.ClientCtx = clientCtx return config } // SetFeeDenom sets the fee denominator parameter. func (config *Config) SetFeeDenom(feeDenom string) *Config { + changeLock.Lock() + defer changeLock.Unlock() config.FeeDenom = feeDenom return config } // SetRoot sets the root directory where to find the keyring. func (config *Config) SetRoot(root string) *Config { + changeLock.Lock() + defer changeLock.Unlock() config.RootDir = root return config } // SetRPCEndpoint sets the RPC endpoint to send requests to. func (config *Config) SetRPCEndpoint(rpcEndpoint string) *Config { + changeLock.Lock() + defer changeLock.Unlock() config.RPCEndpoint = rpcEndpoint return config } // SetTxGas sets the amount of Gas for the TX that is send to the network func (config *Config) SetTxGas(txGas uint64) *Config { + changeLock.Lock() + defer changeLock.Unlock() config.TxGas = txGas return config } diff --git a/lib/tests/e2e/suite.go b/lib/tests/e2e/suite.go index baf2c88..1a13545 100644 --- a/lib/tests/e2e/suite.go +++ b/lib/tests/e2e/suite.go @@ -61,7 +61,7 @@ func (s *E2ETestSuite) TestBankSendBroadcastTxWithFileLock() { assert.Equal(s.T(), "received wrong fee denom; got: plmnt required: stake: invalid coins", txResponse.RawLog) libConfig := lib.GetConfig() - libConfig.FeeDenom = "stake" + libConfig.SetFeeDenom("stake") // incorrect coin out, err = lib.BroadcastTxWithFileLock(val.Address, msg) diff --git a/util/logger.go b/util/logger.go index 4070468..abf6b2c 100644 --- a/util/logger.go +++ b/util/logger.go @@ -16,6 +16,7 @@ var ( globalApplicationLoggerTag string appLogger *AppLogger initAppLogger sync.Once + syncTestingLog sync.Mutex ) func init() { @@ -33,7 +34,9 @@ func GetAppLogger() *AppLogger { } func (logger *AppLogger) SetTestingLogger(testingLogger *testing.T) *AppLogger { + syncTestingLog.Lock() logger.testingLogger = testingLogger + syncTestingLog.Unlock() return logger } @@ -49,7 +52,9 @@ func (logger *AppLogger) testingLog(msg string, keyvals ...interface{}) { return } msg = format(msg, keyvals...) + syncTestingLog.Lock() logger.testingLogger.Logf(msg) + syncTestingLog.Unlock() } func (logger *AppLogger) Info(ctx sdk.Context, msg string, keyvals ...interface{}) {