예제 #1
0
        public GraphQLTestBase(ITestOutputHelper output)
        {
            Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Console().CreateLogger();

            _output = output;

            var goldCurrency = new Currency("NCG", 2, minter: null);

            var fixturePath  = Path.Combine("..", "..", "..", "..", "Lib9c", ".Lib9c.Tests", "Data", "TableCSV");
            var sheets       = TableSheetsImporter.ImportSheets(fixturePath);
            var blockAction  = new RewardGold();
            var genesisBlock = BlockChain <NCAction> .MakeGenesisBlock(
                new NCAction[]
            {
                new InitializeStates(
                    rankingState: new RankingState(),
                    shopState: new ShopState(),
                    gameConfigState: new GameConfigState(sheets[nameof(GameConfigSheet)]),
                    redeemCodeState: new RedeemCodeState(Bencodex.Types.Dictionary.Empty
                                                         .Add("address", RedeemCodeState.Address.Serialize())
                                                         .Add("map", Bencodex.Types.Dictionary.Empty)
                                                         ),
                    adminAddressState: new AdminState(AdminAddress, 10000),
                    activatedAccountsState: new ActivatedAccountsState(),
                    goldCurrencyState: new GoldCurrencyState(goldCurrency),
                    goldDistributions: new GoldDistribution[] { },
                    tableSheets: sheets,
                    pendingActivationStates: new PendingActivationState[] { }
                    ),
            }, blockAction : blockAction);

            var ncService        = ServiceBuilder.CreateNineChroniclesNodeService(genesisBlock, new PrivateKey());
            var tempKeyStorePath = Path.Join(Path.GetTempPath(), Path.GetRandomFileName());
            var keyStore         = new Web3KeyStore(tempKeyStorePath);

            StandaloneContextFx = new StandaloneContext
            {
                KeyStore = keyStore,
            };
            ncService.ConfigureContext(StandaloneContextFx);

            var configurationBuilder = new ConfigurationBuilder();
            var configuration        = configurationBuilder.Build();

            var services = new ServiceCollection();

            services.AddSingleton(StandaloneContextFx);
            services.AddSingleton <IConfiguration>(configuration);
            services.AddGraphTypes();
            services.AddLibplanetExplorer <NCAction>();
            services.AddSingleton <StateQuery>();
            services.AddSingleton(ncService);
            ServiceProvider serviceProvider = services.BuildServiceProvider();

            Schema = new StandaloneSchema(serviceProvider);

            DocumentExecutor = new DocumentExecuter();
        }
        public async Task ActivateAccount()
        {
            var adminPrivateKey = new PrivateKey();
            var adminAddress = adminPrivateKey.ToAddress();
            var activateAccounts = new[] { adminAddress }.ToImmutableHashSet();

            Block <PolymorphicAction <ActionBase> > genesis =
                MakeGenesisBlock(adminAddress, new Currency("NCG", 2, minters: null), activateAccounts);
            NineChroniclesNodeService service = ServiceBuilder.CreateNineChroniclesNodeService(genesis);

            StandaloneContextFx.NineChroniclesNodeService = service;
            StandaloneContextFx.BlockChain = service.Swarm.BlockChain;

            var blockChain = StandaloneContextFx.BlockChain;

            var nonce      = new byte[] { 0x00, 0x01, 0x02, 0x03 };
            var privateKey = new PrivateKey();

            (ActivationKey activationKey, PendingActivationState pendingActivation) =
                ActivationKey.Create(privateKey, nonce);
            PolymorphicAction <ActionBase> action = new CreatePendingActivation(pendingActivation);

            blockChain.MakeTransaction(adminPrivateKey, new[] { action });
            await blockChain.MineBlock(adminAddress);

            var encodedActivationKey = activationKey.Encode();
            var queryResult          = await ExecuteQueryAsync(
                $"mutation {{ activationStatus {{ activateAccount(encodedActivationKey: \"{encodedActivationKey}\") }} }}");

            await blockChain.MineBlock(adminAddress);

            var result = (bool)queryResult.Data
                         .As <Dictionary <string, object> >()["activationStatus"]
                         .As <Dictionary <string, object> >()["activateAccount"];

            Assert.True(result);

            var state = (Bencodex.Types.Dictionary)blockChain.GetState(
                ActivatedAccountsState.Address);
            var     activatedAccountsState = new ActivatedAccountsState(state);
            Address userAddress            = service.PrivateKey.ToAddress();

            Assert.True(activatedAccountsState.Accounts.Contains(userAddress));
        }
예제 #3
0
        public async Task NodeStatusStagedTxIds()
        {
            var apvPrivateKey = new PrivateKey();
            var apv           = AppProtocolVersion.Sign(apvPrivateKey, 0);
            var genesis       = BlockChain <PolymorphicAction <ActionBase> > .MakeGenesisBlock();

            var service = ServiceBuilder.CreateNineChroniclesNodeService(genesis);

            StandaloneServices.ConfigureStandaloneContext(service, StandaloneContextFx);

            var result = await ExecuteQueryAsync("query { nodeStatus { stagedTxIds } }");

            var expectedResult = new Dictionary <string, object>()
            {
                ["nodeStatus"] = new Dictionary <string, object>()
                {
                    ["stagedTxIds"] = new List <object>()
                },
            };

            Assert.Null(result.Errors);
            Assert.Equal(expectedResult, result.Data);

            var tx = StandaloneContextFx.BlockChain.MakeTransaction(
                new PrivateKey(),
                new PolymorphicAction <ActionBase>[] { }
                );

            result = await ExecuteQueryAsync("query { nodeStatus { stagedTxIds } }");

            expectedResult = new Dictionary <string, object>()
            {
                ["nodeStatus"] = new Dictionary <string, object>()
                {
                    ["stagedTxIds"] = new List <object>
                    {
                        tx.Id.ToString(),
                    }
                },
            };
            Assert.Null(result.Errors);
            Assert.Equal(expectedResult, result.Data);
        }