-
Notifications
You must be signed in to change notification settings - Fork 12
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
[Session, Test] Session rollover test #332
Merged
Merged
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bddfe65
feat: Implement session rollover logic
red-0ne 834a012
test: Add session rollover tests
red-0ne 58c43d2
chore: Address change requests
red-0ne 1ff8f78
chore: Fix typo
red-0ne 68bf230
chore: Address change requests
red-0ne 0c54ea4
test: Add session rollover e2e feature description
red-0ne 15cc2fd
Update e2e/tests/session.feature
red-0ne 82f79d1
Update pkg/relayer/proxy/relay_verifier.go
red-0ne 8554c12
Update pkg/relayer/proxy/relay_verifier.go
red-0ne 81e26f5
Update pkg/relayer/session/session.go
red-0ne f73528e
chore: Address change requests
red-0ne 79bf761
Merge remote-tracking branch 'origin/main' into feat/session-rollover
red-0ne df1eec7
fix: Comment unimplemented e2e tests
red-0ne bee3748
Merge branch 'feat/session-rollover' into test/session-rollover
red-0ne 50e9b81
fix: Use GetSessionGracePeriodBlockCount
red-0ne 63b8511
chore: Adapt e2e test to reflect delay
red-0ne 388cb13
Merge branch 'main' into test/session-rollover
red-0ne cf7a144
chore: Remove magic strings
red-0ne 2a55a88
chore: Revert e2e test feature description
red-0ne 7d0e439
Merge remote-tracking branch 'origin/main' into test/session-rollover
red-0ne 0449d02
Empty commit
red-0ne 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 |
---|---|---|
|
@@ -18,10 +18,15 @@ import ( | |
"github.com/pokt-network/poktroll/pkg/relayer/proxy" | ||
"github.com/pokt-network/poktroll/testutil/testproxy" | ||
servicetypes "github.com/pokt-network/poktroll/x/service/types" | ||
sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper" | ||
sharedtypes "github.com/pokt-network/poktroll/x/shared/types" | ||
) | ||
|
||
const blockHeight = 1 | ||
const ( | ||
blockHeight = 1 | ||
defaultService = "service1" | ||
defaultServer = "server1" | ||
) | ||
|
||
var ( | ||
// helpers used for tests that are initialized in init() | ||
|
@@ -75,12 +80,12 @@ func init() { | |
|
||
proxiedServices = map[string]*config.RelayMinerProxyConfig{ | ||
"server1": { | ||
ProxyName: "server1", | ||
ProxyName: defaultServer, | ||
Type: config.ProxyTypeHTTP, | ||
Host: "127.0.0.1:8080", | ||
Suppliers: map[string]*config.RelayMinerSupplierConfig{ | ||
"service1": { | ||
ServiceId: "service1", | ||
ServiceId: defaultService, | ||
Type: config.ProxyTypeHTTP, | ||
Hosts: []string{"supplier:8545"}, | ||
ServiceConfig: &config.RelayMinerSupplierServiceConfig{ | ||
|
@@ -115,11 +120,11 @@ func init() { | |
} | ||
|
||
defaultRelayerProxyBehavior = []func(*testproxy.TestBehavior){ | ||
testproxy.WithRelayerProxyDependencies(supplierKeyName), | ||
testproxy.WithRelayerProxyDependenciesForBlockHeight(supplierKeyName, blockHeight), | ||
testproxy.WithRelayerProxiedServices(proxiedServices), | ||
testproxy.WithDefaultSupplier(supplierKeyName, supplierEndpoints), | ||
testproxy.WithDefaultApplication(appPrivateKey), | ||
testproxy.WithDefaultSessionSupplier(supplierKeyName, "service1", appPrivateKey), | ||
testproxy.WithDefaultSessionSupplier(supplierKeyName, defaultService, appPrivateKey), | ||
} | ||
} | ||
|
||
|
@@ -143,7 +148,7 @@ func TestRelayerProxy_StartAndStop(t *testing.T) { | |
time.Sleep(100 * time.Millisecond) | ||
|
||
// Test that RelayerProxy is handling requests (ignoring the actual response content) | ||
res, err := http.DefaultClient.Get(fmt.Sprintf("http://%s/", proxiedServices["server1"].Host)) | ||
res, err := http.DefaultClient.Get(fmt.Sprintf("http://%s/", proxiedServices[defaultServer].Host)) | ||
require.NoError(t, err) | ||
require.NotNil(t, res) | ||
|
||
|
@@ -216,13 +221,13 @@ func TestRelayerProxy_UnsupportedRpcType(t *testing.T) { | |
} | ||
|
||
unsupportedRPCTypeBehavior := []func(*testproxy.TestBehavior){ | ||
testproxy.WithRelayerProxyDependencies(supplierKeyName), | ||
testproxy.WithRelayerProxyDependenciesForBlockHeight(supplierKeyName, blockHeight), | ||
testproxy.WithRelayerProxiedServices(proxiedServices), | ||
|
||
// The supplier is staked on-chain but the service it provides is not supported by the proxy | ||
testproxy.WithDefaultSupplier(supplierKeyName, unsupportedSupplierEndpoint), | ||
testproxy.WithDefaultApplication(appPrivateKey), | ||
testproxy.WithDefaultSessionSupplier(supplierKeyName, "service1", appPrivateKey), | ||
testproxy.WithDefaultSessionSupplier(supplierKeyName, defaultService, appPrivateKey), | ||
} | ||
|
||
test := testproxy.NewRelayerProxyTestBehavior(ctx, t, unsupportedRPCTypeBehavior...) | ||
|
@@ -252,13 +257,13 @@ func TestRelayerProxy_UnsupportedTransportType(t *testing.T) { | |
|
||
unsupportedTransportProxy := map[string]*config.RelayMinerProxyConfig{ | ||
"server1": { | ||
ProxyName: "server1", | ||
ProxyName: defaultServer, | ||
// The proxy is configured with an unsupported transport type | ||
Type: config.ProxyType(100), | ||
Host: "127.0.0.1:8080", | ||
Suppliers: map[string]*config.RelayMinerSupplierConfig{ | ||
"service1": { | ||
ServiceId: "service1", | ||
ServiceId: defaultService, | ||
// The proxy is configured with an unsupported transport type | ||
Type: config.ProxyType(100), | ||
Hosts: []string{"supplier:8545"}, | ||
|
@@ -271,13 +276,13 @@ func TestRelayerProxy_UnsupportedTransportType(t *testing.T) { | |
} | ||
|
||
unsupportedTransportTypeBehavior := []func(*testproxy.TestBehavior){ | ||
testproxy.WithRelayerProxyDependencies(supplierKeyName), | ||
testproxy.WithRelayerProxyDependenciesForBlockHeight(supplierKeyName, blockHeight), | ||
|
||
// The proxy is configured with an unsupported transport type for the proxy | ||
testproxy.WithRelayerProxiedServices(unsupportedTransportProxy), | ||
testproxy.WithDefaultSupplier(supplierKeyName, badTransportSupplierEndpoints), | ||
testproxy.WithDefaultApplication(appPrivateKey), | ||
testproxy.WithDefaultSessionSupplier(supplierKeyName, "service1", appPrivateKey), | ||
testproxy.WithDefaultSessionSupplier(supplierKeyName, defaultService, appPrivateKey), | ||
} | ||
|
||
test := testproxy.NewRelayerProxyTestBehavior(ctx, t, unsupportedTransportTypeBehavior...) | ||
|
@@ -298,12 +303,12 @@ func TestRelayerProxy_NonConfiguredSupplierServices(t *testing.T) { | |
|
||
missingServicesProxy := map[string]*config.RelayMinerProxyConfig{ | ||
"server1": { | ||
ProxyName: "server1", | ||
ProxyName: defaultServer, | ||
Type: config.ProxyTypeHTTP, | ||
Host: "127.0.0.1:8080", | ||
Suppliers: map[string]*config.RelayMinerSupplierConfig{ | ||
"service1": { | ||
ServiceId: "service1", | ||
ServiceId: defaultService, | ||
Type: config.ProxyTypeHTTP, | ||
Hosts: []string{"supplier:8545"}, | ||
ServiceConfig: &config.RelayMinerSupplierServiceConfig{ | ||
|
@@ -315,13 +320,13 @@ func TestRelayerProxy_NonConfiguredSupplierServices(t *testing.T) { | |
} | ||
|
||
unsupportedTransportTypeBehavior := []func(*testproxy.TestBehavior){ | ||
testproxy.WithRelayerProxyDependencies(supplierKeyName), | ||
testproxy.WithRelayerProxyDependenciesForBlockHeight(supplierKeyName, blockHeight), | ||
|
||
// The proxy is configured with an unsupported transport type for the proxy | ||
testproxy.WithRelayerProxiedServices(missingServicesProxy), | ||
testproxy.WithDefaultSupplier(supplierKeyName, supplierEndpoints), | ||
testproxy.WithDefaultApplication(appPrivateKey), | ||
testproxy.WithDefaultSessionSupplier(supplierKeyName, "service1", appPrivateKey), | ||
testproxy.WithDefaultSessionSupplier(supplierKeyName, defaultService, appPrivateKey), | ||
} | ||
|
||
test := testproxy.NewRelayerProxyTestBehavior(ctx, t, unsupportedTransportTypeBehavior...) | ||
|
@@ -339,6 +344,12 @@ func TestRelayerProxy_NonConfiguredSupplierServices(t *testing.T) { | |
|
||
// Test different RelayRequest scenarios | ||
func TestRelayerProxy_Relays(t *testing.T) { | ||
// blockWithinTheThirdSession is the block height that is past the first session's | ||
// grace period and within the second session's grace period | ||
var blockWithinTheThirdSession int64 = blockHeight + | ||
red-0ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sessionkeeper.NumBlocksPerSession + | ||
sessionkeeper.SessionGracePeriod | ||
|
||
tests := []struct { | ||
desc string | ||
// RelayerProxy instrumented behavior | ||
|
@@ -432,12 +443,12 @@ func TestRelayerProxy_Relays(t *testing.T) { | |
desc: "Invalid relay supplier", | ||
|
||
relayerProxyBehavior: []func(*testproxy.TestBehavior){ | ||
testproxy.WithRelayerProxyDependencies(supplierKeyName), | ||
testproxy.WithRelayerProxyDependenciesForBlockHeight(supplierKeyName, blockHeight), | ||
testproxy.WithRelayerProxiedServices(proxiedServices), | ||
testproxy.WithDefaultSupplier(supplierKeyName, supplierEndpoints), | ||
testproxy.WithDefaultApplication(appPrivateKey), | ||
// Missing session supplier | ||
testproxy.WithDefaultSessionSupplier("", "service1", appPrivateKey), | ||
testproxy.WithDefaultSessionSupplier("", defaultService, appPrivateKey), | ||
}, | ||
inputScenario: sendRequestWithInvalidRelaySupplier, | ||
|
||
|
@@ -462,6 +473,50 @@ func TestRelayerProxy_Relays(t *testing.T) { | |
expectedErrCode: 0, | ||
expectedErrMsg: "", | ||
}, | ||
{ | ||
desc: "Successful late relay with session grace period", | ||
|
||
relayerProxyBehavior: []func(*testproxy.TestBehavior){ | ||
// blockHeight is past the first session but within its session grace period | ||
testproxy.WithRelayerProxyDependenciesForBlockHeight( | ||
supplierKeyName, | ||
blockHeight+sessionkeeper.SessionGracePeriod, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be solved by the base PR, but it's unclear if SessionGracePeriod is NumBlocks, NumSessions, etc... After renaming it in the other PR, this should be solved though. |
||
), | ||
testproxy.WithRelayerProxiedServices(proxiedServices), | ||
testproxy.WithDefaultSupplier(supplierKeyName, supplierEndpoints), | ||
testproxy.WithDefaultApplication(appPrivateKey), | ||
// Add 2 sessions, with the first one being within the withing grace period | ||
// and the second one being the current session | ||
testproxy.WithSuccessiveSessions(supplierKeyName, defaultService, appPrivateKey, 2), | ||
}, | ||
inputScenario: sendRequestWithCustomSessionHeight(blockHeight), | ||
|
||
expectedErrCode: 0, | ||
expectedErrMsg: "", | ||
red-0ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
{ | ||
desc: "Failed late relay outside session grace period", | ||
|
||
relayerProxyBehavior: []func(*testproxy.TestBehavior){ | ||
// blockHeight is past the first session's grace period | ||
testproxy.WithRelayerProxyDependenciesForBlockHeight( | ||
supplierKeyName, | ||
// Set the current block height value returned by the block provider | ||
blockWithinTheThirdSession, | ||
), | ||
testproxy.WithRelayerProxiedServices(proxiedServices), | ||
testproxy.WithDefaultSupplier(supplierKeyName, supplierEndpoints), | ||
testproxy.WithDefaultApplication(appPrivateKey), | ||
// Add 3 sessions, with the first one that is no longer within its | ||
// session grace period | ||
testproxy.WithSuccessiveSessions(supplierKeyName, defaultService, appPrivateKey, 3), | ||
}, | ||
// Send a request that has a late session past the grace period | ||
inputScenario: sendRequestWithCustomSessionHeight(blockHeight), | ||
|
||
expectedErrCode: -32000, | ||
expectedErrMsg: "session expired", | ||
red-0ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
} | ||
|
||
ctx := context.TODO() | ||
|
@@ -498,7 +553,7 @@ func sendRequestWithUnparsableBody( | |
reader := io.NopCloser(bytes.NewReader([]byte("invalid request"))) | ||
|
||
res, err := http.DefaultClient.Post( | ||
fmt.Sprintf("http://%s", proxiedServices["server1"].Host), | ||
fmt.Sprintf("http://%s", proxiedServices[defaultServer].Host), | ||
"application/json", | ||
reader, | ||
) | ||
|
@@ -518,7 +573,7 @@ func sendRequestWithMissingMeta( | |
Payload: testproxy.PrepareJsonRPCRequestPayload(), | ||
} | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
func sendRequestWithMissingSignature( | ||
|
@@ -528,12 +583,12 @@ func sendRequestWithMissingSignature( | |
req := testproxy.GenerateRelayRequest( | ||
test, | ||
appPrivateKey, | ||
"service1", | ||
defaultService, | ||
blockHeight, | ||
testproxy.PrepareJsonRPCRequestPayload(), | ||
) | ||
req.Meta.Signature = nil | ||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
func sendRequestWithInvalidSignature( | ||
|
@@ -543,13 +598,13 @@ func sendRequestWithInvalidSignature( | |
req := testproxy.GenerateRelayRequest( | ||
test, | ||
appPrivateKey, | ||
"service1", | ||
defaultService, | ||
blockHeight, | ||
testproxy.PrepareJsonRPCRequestPayload(), | ||
) | ||
req.Meta.Signature = []byte("invalid signature") | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
func sendRequestWithMissingSessionHeaderApplicationAddress( | ||
|
@@ -560,7 +615,7 @@ func sendRequestWithMissingSessionHeaderApplicationAddress( | |
req := testproxy.GenerateRelayRequest( | ||
test, | ||
randomPrivKey, | ||
"service1", | ||
defaultService, | ||
blockHeight, | ||
testproxy.PrepareJsonRPCRequestPayload(), | ||
) | ||
|
@@ -572,7 +627,7 @@ func sendRequestWithMissingSessionHeaderApplicationAddress( | |
// before looking at the application address | ||
req.Meta.Signature = testproxy.GetApplicationRingSignature(t, req, randomPrivKey) | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
func sendRequestWithNonStakedApplicationAddress( | ||
|
@@ -583,15 +638,15 @@ func sendRequestWithNonStakedApplicationAddress( | |
req := testproxy.GenerateRelayRequest( | ||
test, | ||
randomPrivKey, | ||
"service1", | ||
defaultService, | ||
blockHeight, | ||
testproxy.PrepareJsonRPCRequestPayload(), | ||
) | ||
|
||
// Have a valid signature from the non staked key | ||
req.Meta.Signature = testproxy.GetApplicationRingSignature(t, req, randomPrivKey) | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
func sendRequestWithRingSignatureMismatch( | ||
|
@@ -601,7 +656,7 @@ func sendRequestWithRingSignatureMismatch( | |
req := testproxy.GenerateRelayRequest( | ||
test, | ||
appPrivateKey, | ||
"service1", | ||
defaultService, | ||
blockHeight, | ||
testproxy.PrepareJsonRPCRequestPayload(), | ||
) | ||
|
@@ -610,7 +665,7 @@ func sendRequestWithRingSignatureMismatch( | |
randomPrivKey := secp256k1.GenPrivKey() | ||
req.Meta.Signature = testproxy.GetApplicationRingSignature(t, req, randomPrivKey) | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
func sendRequestWithDifferentSession( | ||
|
@@ -627,7 +682,7 @@ func sendRequestWithDifferentSession( | |
) | ||
req.Meta.Signature = testproxy.GetApplicationRingSignature(t, req, appPrivateKey) | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
func sendRequestWithInvalidRelaySupplier( | ||
|
@@ -637,13 +692,13 @@ func sendRequestWithInvalidRelaySupplier( | |
req := testproxy.GenerateRelayRequest( | ||
test, | ||
appPrivateKey, | ||
"service1", | ||
defaultService, | ||
blockHeight, | ||
testproxy.PrepareJsonRPCRequestPayload(), | ||
) | ||
req.Meta.Signature = testproxy.GetApplicationRingSignature(t, req, appPrivateKey) | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
func sendRequestWithSignatureForDifferentPayload( | ||
|
@@ -652,7 +707,7 @@ func sendRequestWithSignatureForDifferentPayload( | |
) (errCode int32, errorMessage string) { | ||
req := testproxy.GenerateRelayRequest( | ||
test, appPrivateKey, | ||
"service1", | ||
defaultService, | ||
blockHeight, | ||
testproxy.PrepareJsonRPCRequestPayload(), | ||
) | ||
|
@@ -661,7 +716,7 @@ func sendRequestWithSignatureForDifferentPayload( | |
// Alter the request payload so the hash doesn't match the one used by the signature | ||
req.Payload = []byte(`{"method":"someMethod","id":1,"jsonrpc":"2.0","params":["alteredParam"]}`) | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
func sendRequestWithSuccessfulReply( | ||
|
@@ -671,11 +726,31 @@ func sendRequestWithSuccessfulReply( | |
req := testproxy.GenerateRelayRequest( | ||
test, | ||
appPrivateKey, | ||
"service1", | ||
defaultService, | ||
blockHeight, | ||
testproxy.PrepareJsonRPCRequestPayload(), | ||
) | ||
req.Meta.Signature = testproxy.GetApplicationRingSignature(t, req, appPrivateKey) | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, "server1", "service1", req) | ||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
|
||
// sendRequestWithCustomSessionHeight is a helper function that generates a `RelayRequest` | ||
// with a `Session` that contains the given `requestSessionBlockHeight` and sends it to the | ||
// `RelayerProxy`. | ||
func sendRequestWithCustomSessionHeight( | ||
red-0ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requestSessionBlockHeight int64, | ||
) func(t *testing.T, test *testproxy.TestBehavior) (errCode int32, errorMessage string) { | ||
return func(t *testing.T, test *testproxy.TestBehavior) (errCode int32, errorMessage string) { | ||
req := testproxy.GenerateRelayRequest( | ||
test, | ||
appPrivateKey, | ||
defaultService, | ||
requestSessionBlockHeight, | ||
testproxy.PrepareJsonRPCRequestPayload(), | ||
) | ||
req.Meta.Signature = testproxy.GetApplicationRingSignature(t, req, appPrivateKey) | ||
|
||
return testproxy.MarshalAndSend(test, proxiedServices, defaultServer, defaultService, req) | ||
} | ||
} |
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.
This is an ultra NIT, but something I'm asking for just because I also always get confused between proxy/server/etc...
Do the key and
proxyName
need to be the same or can they be different?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.
You are right, it's confusing.
The key and
ProxyName
have to be the same, as the config parser maps the proxy servers using theirProxyName
as keys.I was uncomfortable having a variable as a key but afterthought, I believe it will add more clarity. Let's having as