-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci(tests): historacle e2e #1687
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
114c73b
grpc test setup
zarazan 014bd10
add umee client
zarazan 570d38e
UmeeClient updates WIP
zarazan 4b901c4
update e2e genesis
zarazan edcf93f
add testing price_store
zarazan 5d1c910
price store update
zarazan 2a9c842
set chain id
adamewozniak d2f853f
Merge branch 'main' into zarazan/grpc-test
adamewozniak 27fa242
price feeder gas fix
adamewozniak 0516d85
update e2e test price feeder config
zarazan 40b49cb
fix IBC tests
adamewozniak 9e4c815
check all accepted denom medians
zarazan 6f64053
Merge remote-tracking branch 'origin/zarazan/grpc-test' into zarazan/…
zarazan f44143e
remove extra prints
zarazan b84929b
Merge branch 'main' into zarazan/grpc-test
adamewozniak d9c77d4
add error
zarazan fde64a0
Merge remote-tracking branch 'origin/zarazan/grpc-test' into zarazan/…
zarazan 9961ed2
linter fixes
zarazan 62dd199
Merge branch 'main' into zarazan/grpc-test
adamewozniak File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,6 @@ dist/ | |
|
||
# OSX | ||
*.DS_Store | ||
|
||
# e2e test keychain folder | ||
tests/e2e/keyring-test |
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,112 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"sync" | ||
|
||
"github.com/rs/zerolog" | ||
tmrpcclient "github.com/tendermint/tendermint/rpc/client" | ||
tmctypes "github.com/tendermint/tendermint/rpc/core/types" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
) | ||
|
||
var ( | ||
errParseEventDataNewBlockHeader = errors.New("error parsing EventDataNewBlockHeader") | ||
queryEventNewBlockHeader = tmtypes.QueryForEvent(tmtypes.EventNewBlockHeader) | ||
) | ||
|
||
// ChainHeight is used to cache the chain height of the | ||
// current node which is being updated each time the | ||
// node sends an event of EventNewBlockHeader. | ||
// It starts a goroutine to subscribe to blockchain new block event and update the cached height. | ||
type ChainHeight struct { | ||
Logger zerolog.Logger | ||
|
||
mtx sync.RWMutex | ||
errGetChainHeight error | ||
lastChainHeight int64 | ||
HeightChanged chan (int64) | ||
} | ||
|
||
// NewChainHeight returns a new ChainHeight struct that | ||
// starts a new goroutine subscribed to EventNewBlockHeader. | ||
func NewChainHeight( | ||
ctx context.Context, | ||
rpcClient tmrpcclient.Client, | ||
logger zerolog.Logger, | ||
) (*ChainHeight, error) { | ||
if !rpcClient.IsRunning() { | ||
if err := rpcClient.Start(); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
newBlockHeaderSubscription, err := rpcClient.Subscribe( | ||
ctx, tmtypes.EventNewBlockHeader, queryEventNewBlockHeader.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
chainHeight := &ChainHeight{ | ||
Logger: logger.With().Str("oracle_client", "chain_height").Logger(), | ||
} | ||
chainHeight.HeightChanged = make(chan int64) | ||
|
||
go chainHeight.subscribe(ctx, rpcClient, newBlockHeaderSubscription) | ||
|
||
return chainHeight, nil | ||
} | ||
|
||
// updateChainHeight receives the data to be updated thread safe. | ||
func (chainHeight *ChainHeight) updateChainHeight(blockHeight int64, err error) { | ||
chainHeight.mtx.Lock() | ||
defer chainHeight.mtx.Unlock() | ||
|
||
if chainHeight.lastChainHeight != blockHeight { | ||
select { | ||
case chainHeight.HeightChanged <- blockHeight: | ||
default: | ||
} | ||
} | ||
chainHeight.lastChainHeight = blockHeight | ||
chainHeight.errGetChainHeight = err | ||
} | ||
|
||
// subscribe listens to new blocks being made | ||
// and updates the chain height. | ||
func (chainHeight *ChainHeight) subscribe( | ||
ctx context.Context, | ||
eventsClient tmrpcclient.EventsClient, | ||
newBlockHeaderSubscription <-chan tmctypes.ResultEvent, | ||
) { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
err := eventsClient.Unsubscribe(ctx, tmtypes.EventNewBlockHeader, queryEventNewBlockHeader.String()) | ||
if err != nil { | ||
chainHeight.Logger.Err(err) | ||
chainHeight.updateChainHeight(chainHeight.lastChainHeight, err) | ||
} | ||
chainHeight.Logger.Info().Msg("closing the ChainHeight subscription") | ||
return | ||
|
||
case resultEvent := <-newBlockHeaderSubscription: | ||
eventDataNewBlockHeader, ok := resultEvent.Data.(tmtypes.EventDataNewBlockHeader) | ||
if !ok { | ||
chainHeight.Logger.Err(errParseEventDataNewBlockHeader) | ||
chainHeight.updateChainHeight(chainHeight.lastChainHeight, errParseEventDataNewBlockHeader) | ||
continue | ||
} | ||
chainHeight.updateChainHeight(eventDataNewBlockHeader.Header.Height, nil) | ||
} | ||
} | ||
} | ||
|
||
// GetChainHeight returns the last chain height available. | ||
func (chainHeight *ChainHeight) GetChainHeight() (int64, error) { | ||
chainHeight.mtx.RLock() | ||
defer chainHeight.mtx.RUnlock() | ||
|
||
return chainHeight.lastChainHeight, chainHeight.errGetChainHeight | ||
} |
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 grpc | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"strings" | ||
) | ||
|
||
func dialerFunc(_ context.Context, addr string) (net.Conn, error) { | ||
return Connect(addr) | ||
} | ||
|
||
// Connect dials the given address and returns a net.Conn. The protoAddr | ||
// argument should be prefixed with the protocol, | ||
// eg. "tcp://127.0.0.1:8080" or "unix:///tmp/test.sock". | ||
func Connect(protoAddr string) (net.Conn, error) { | ||
proto, address := ProtocolAndAddress(protoAddr) | ||
conn, err := net.Dial(proto, address) | ||
return conn, err | ||
} | ||
|
||
// ProtocolAndAddress splits an address into the protocol and address components. | ||
// For instance, "tcp://127.0.0.1:8080" will be split into "tcp" and "127.0.0.1:8080". | ||
// If the address has no protocol prefix, the default is "tcp". | ||
func ProtocolAndAddress(listenAddr string) (string, string) { | ||
protocol, address := "tcp", listenAddr | ||
|
||
parts := strings.SplitN(address, "://", 2) | ||
if len(parts) == 2 { | ||
protocol, address = parts[0], parts[1] | ||
} | ||
|
||
return protocol, address | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why adding these comments? it's "purple prose"