Skip to content

Commit

Permalink
itest: test UniverseInfo RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Jun 19, 2023
1 parent 2e6eac1 commit 3bd9bc3
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions itest/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,39 @@ func testUniverseFederation(t *harnessTest) {
require.NoError(t.t, bob.stop(true))
}()

ctx := context.Background()
ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
defer cancel()

// Now that Bob is active, we'll make a set of assets with the main node.
firstAsset := mintAssetsConfirmBatch(t, t.tapd, simpleAssets[:1])
require.Len(t.t, firstAsset, 1)

// Make sure we can't add ourselves to the universe.
_, err := t.tapd.AddFederationServer(
ctxt, &unirpc.AddFederationServerRequest{
Servers: []*unirpc.UniverseFederationServer{{
Host: t.tapd.rpcHost(),
}},
},
)
require.ErrorContains(t.t, err, "cannot add ourselves")

// Make sure we can't add an invalid server to the universe.
_, err = t.tapd.AddFederationServer(
ctxt, &unirpc.AddFederationServerRequest{
Servers: []*unirpc.UniverseFederationServer{{
Host: "foobar this is not even a valid address",
}},
},
)
require.ErrorContains(t.t, err, "no such host")

// We'll now add the main node, as a member of Bob's Universe
// federation. We expect that their state is synchronized shortly after
// the call returns.
_, err := bob.AddFederationServer(
ctx, &unirpc.AddFederationServerRequest{
_, err = bob.AddFederationServer(
ctxt, &unirpc.AddFederationServerRequest{
Servers: []*unirpc.UniverseFederationServer{
{
Host: t.tapd.rpcHost(),
Expand All @@ -292,7 +314,7 @@ func testUniverseFederation(t *harnessTest) {
// If we fetch the set of federation nodes, then the main node should
// be shown as being a part of that set.
fedNodes, err := bob.ListFederationServers(
ctx, &unirpc.ListFederationServersRequest{},
ctxt, &unirpc.ListFederationServersRequest{},
)
require.NoError(t.t, err)
require.Equal(t.t, 1, len(fedNodes.Servers))
Expand All @@ -307,14 +329,19 @@ func testUniverseFederation(t *harnessTest) {
// should also be able to query for stats specifically for the asset.
assertUniverseStats(t.t, bob, 1, 0, 1)

// Test the content of the universe info call.
info, err := bob.Info(ctxt, &unirpc.InfoRequest{})
require.NoError(t.t, err)
require.EqualValues(t.t, 1, info.NumAssets)

// We'll now make a new asset with Bob, and ensure that the state is
// properly pushed to the main node which is a part of the federation.
newAsset := mintAssetsConfirmBatch(t, bob, simpleAssets[1:])

// Bob should have a new asset in its local Universe tree.
assetID := newAsset[0].AssetGenesis.AssetId
waitErr := wait.NoError(func() error {
_, err := bob.QueryAssetRoots(ctx, &unirpc.AssetRootQuery{
_, err := bob.QueryAssetRoots(ctxt, &unirpc.AssetRootQuery{
Id: &unirpc.ID{
Id: &unirpc.ID_AssetId{
AssetId: assetID,
Expand Down Expand Up @@ -345,7 +372,7 @@ func testUniverseFederation(t *harnessTest) {

// Next, we'll try to delete the main node from the federation.
_, err = bob.DeleteFederationServer(
ctx, &unirpc.DeleteFederationServerRequest{
ctxt, &unirpc.DeleteFederationServerRequest{
Servers: []*unirpc.UniverseFederationServer{
{
Host: t.tapd.rpcHost(),
Expand All @@ -358,7 +385,7 @@ func testUniverseFederation(t *harnessTest) {
// If we fetch the set of federation nodes, then the main node should
// no longer be present.
fedNodes, err = bob.ListFederationServers(
ctx, &unirpc.ListFederationServersRequest{},
ctxt, &unirpc.ListFederationServersRequest{},
)
require.NoError(t.t, err)
require.Equal(t.t, 0, len(fedNodes.Servers))
Expand Down

0 comments on commit 3bd9bc3

Please sign in to comment.