-
Notifications
You must be signed in to change notification settings - Fork 5
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
Baseledger p2p client #16
Open
skosito
wants to merge
15
commits into
dev2
Choose a base branch
from
baseledger-p2p-client
base: dev2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
305220e
Add skeleton baseledger p2p client
skosito 962a62c
Add first version of tx receipt
skosito d207ec4
Add baseledger network stats data source factory
skosito be359c8
Make tx receipt more generic
skosito 1d8bb09
Bump provide-go
skosito 7b08093
Use types for provide-go and remove tmp structs
skosito 2866b16
Format tx receipt hashes
skosito 2809ac8
Fix unmarshalling format
skosito 130b676
Bump provide-go and use proper header response
skosito 12b08af
Add first version of stats daemon test
skosito eb9b401
Remove not needed test channel and use stats daemon queue
skosito 710c794
Utilize gingko framework
skosito dd4e7e8
Use evict daemon method instead of just shutting it down
skosito 086b0dc
Add separate scripts for running statsdaemon tests
skosito e0e8fab
Cleanup logging in statsdaemon and tx packages
kthomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 |
---|---|---|
@@ -1,17 +1,135 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
uuid "github.com/kthomas/go.uuid" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/provideplatform/ident/common" | ||
"github.com/provideplatform/nchain/network" | ||
ident "github.com/provideplatform/provide-go/api/ident" | ||
"github.com/provideplatform/provide-go/api/nchain" | ||
) | ||
|
||
func TestNChainStatsdaemon(t *testing.T) { | ||
type chainSpecConfig struct{} | ||
|
||
type chainSpec struct { | ||
Config *chainSpecConfig `json:"config"` | ||
} | ||
|
||
type chainConfig struct { | ||
NativeCurrency *string `json:"native_currency"` | ||
IsBaseledgerNetwork bool `json:"is_baseledger_network"` | ||
Client *string `json:"client"` | ||
BlockExplorerUrl *string `json:"block_explorer_url"` | ||
JsonRpcUrl *string `json:"json_rpc_url"` | ||
WebsocketUrl *string `json:"websocket_url"` | ||
Platform *string `json:"platform"` | ||
EngineID *string `json:"engine_id"` | ||
Chain *string `json:"chain"` | ||
ProtocolID *string `json:"protocol_id"` | ||
NetworkID int `json:"network_id"` | ||
ChainSpec *chainSpec `json:"chainspec"` | ||
} | ||
|
||
type chainDef struct { | ||
Name *string `json:"name"` | ||
Enabled bool `json:"enabled"` | ||
Config *chainConfig `json:"config"` | ||
} | ||
|
||
func SetupBaseledgerTestNetwork() (*network.Network, error) { | ||
testID, _ := uuid.NewV4() | ||
|
||
email := "prvd" + testID.String() + "@email.com" | ||
pwd := "super_secret" | ||
_, err := ident.CreateUser("", map[string]interface{}{ | ||
"first_name": "statsdaemon first name" + testID.String(), | ||
"last_name": "statsdaemon last name" + testID.String(), | ||
"email": email, | ||
"password": pwd, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating user. Error: %s", err.Error()) | ||
} | ||
|
||
authResponse, _ := ident.Authenticate(email, pwd) | ||
if err != nil { | ||
return nil, fmt.Errorf("error authenticating user. Error: %s", err.Error()) | ||
} | ||
|
||
chainySpecConfig := chainSpecConfig{} | ||
chainySpec := chainSpec{ | ||
Config: &chainySpecConfig, | ||
} | ||
chainyConfig := chainConfig{ | ||
NativeCurrency: common.StringOrNil("token"), | ||
Platform: common.StringOrNil("tendermint"), | ||
Client: common.StringOrNil("baseledger"), | ||
NetworkID: 3, | ||
IsBaseledgerNetwork: true, | ||
Chain: common.StringOrNil("peachtree"), | ||
WebsocketUrl: common.StringOrNil("ws://genesis.peachtree.baseledger.provide.network:1337/websocket"), | ||
ChainSpec: &chainySpec, | ||
} | ||
|
||
chainName := fmt.Sprintf("Baseledger Testnet %s", testID.String()) | ||
|
||
chainyChain := chainDef{ | ||
Name: common.StringOrNil(chainName), | ||
Config: &chainyConfig, | ||
} | ||
|
||
chainyChainJSON, _ := json.Marshal(chainyChain) | ||
|
||
params := map[string]interface{}{} | ||
json.Unmarshal(chainyChainJSON, ¶ms) | ||
|
||
testNetwork, err := nchain.CreateNetwork(*authResponse.Token.AccessToken, params) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating network. Error: %s", err.Error()) | ||
} | ||
|
||
return &network.Network{ | ||
ApplicationID: testNetwork.ApplicationID, | ||
UserID: testNetwork.UserID, | ||
Name: testNetwork.Name, | ||
Description: testNetwork.Description, | ||
Enabled: testNetwork.Enabled, | ||
ChainID: testNetwork.ChainID, | ||
NetworkID: testNetwork.NetworkID, | ||
Config: testNetwork.Config, | ||
}, nil | ||
} | ||
|
||
func TestNChainBaseledgerStatsdaemon(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "NChain statsdaemon Suite") | ||
} | ||
|
||
var _ = Describe("Main", func() { | ||
It("Should parse one successful baseledger block header event", func() { | ||
testNetwork, err := SetupBaseledgerTestNetwork() | ||
if err != nil { | ||
Fail("Failed to set up baseledger test network") | ||
} | ||
|
||
statsDaemon := RequireNetworkStatsDaemon(testNetwork) | ||
// get one result and shutdown statsdaemon and check result | ||
sampleResult := <-statsDaemon.queue | ||
EvictNetworkStatsDaemon(testNetwork) | ||
|
||
jsonSampleResult, _ := json.Marshal(sampleResult.Meta["last_block_header"]) | ||
formattedSampleHeaderResult := nchain.BaseledgerBlockHeaderResponse{}.Value.Header | ||
err = json.Unmarshal(jsonSampleResult, &formattedSampleHeaderResult) | ||
if err != nil { | ||
Fail("Failed to unmarshall header response") | ||
} | ||
|
||
Expect(formattedSampleHeaderResult).NotTo(BeNil()) | ||
}) | ||
}) |
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
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.
🔥
NewBlockHeader
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.
do we need different event? i was using this one, from tendermint
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.
this is good.