From 78597562f0f93c99129bc49e75f7b851766e5052 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 15 Jun 2023 16:05:51 +0200 Subject: [PATCH] itest: test UniverseInfo RPC --- itest/universe_test.go | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/itest/universe_test.go b/itest/universe_test.go index e349cab52..a98db9554 100644 --- a/itest/universe_test.go +++ b/itest/universe_test.go @@ -268,17 +268,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(), @@ -291,7 +313,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)) @@ -304,6 +326,12 @@ 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) + require.EqualValues(t.t, 1, info.NumSyncServers) + // 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:]) @@ -311,7 +339,7 @@ func testUniverseFederation(t *harnessTest) { // 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, @@ -342,7 +370,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(), @@ -355,7 +383,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))