Beispiel #1
0
        public async Task DoesTransactionFollowsPolicy()
        {
            var adminPrivateKey     = new PrivateKey();
            var adminAddress        = adminPrivateKey.ToAddress();
            var activatedPrivateKey = new PrivateKey();
            var activatedAddress    = activatedPrivateKey.ToAddress();

            IBlockPolicy <PolymorphicAction <ActionBase> > policy   = BlockPolicy.GetPolicy(10000);
            IRenderer <PolymorphicAction <ActionBase> >    renderer = BlockPolicy.GetRenderer();
            Block <PolymorphicAction <ActionBase> >        genesis  = MakeGenesisBlock(
                adminAddress,
                ImmutableHashSet.Create(activatedAddress).Add(adminAddress)
                );

            using var store = new DefaultStore(null);
            var blockChain = new BlockChain <PolymorphicAction <ActionBase> >(
                policy,
                store,
                store,
                genesis,
                renderers: new[] { renderer }
                );
            Transaction <PolymorphicAction <ActionBase> > txByStranger =
                Transaction <PolymorphicAction <ActionBase> > .Create(
                    0,
                    new PrivateKey(),
                    genesis.Hash,
                    new PolymorphicAction <ActionBase>[] { }
                    );

            // 새로 만든 키는 활성화 유저 리스트에 없기 때문에 차단됩니다.
            Assert.False(policy.DoesTransactionFollowsPolicy(txByStranger));

            var newActivatedPrivateKey = new PrivateKey();
            var newActivatedAddress    = newActivatedPrivateKey.ToAddress();

            // 관리자 계정으로 활성화 시킵니다.
            Transaction <PolymorphicAction <ActionBase> > invitationTx = blockChain.MakeTransaction(
                adminPrivateKey,
                new PolymorphicAction <ActionBase>[] { new AddActivatedAccount(newActivatedAddress) }
                );

            blockChain.StageTransaction(invitationTx);
            await blockChain.MineBlock(adminAddress);

            Transaction <PolymorphicAction <ActionBase> > txByNewActivated =
                Transaction <PolymorphicAction <ActionBase> > .Create(
                    0,
                    newActivatedPrivateKey,
                    genesis.Hash,
                    new PolymorphicAction <ActionBase>[] { }
                    );

            // 활성화 된 계정이기 때문에 테스트에 성공합니다.
            Assert.True(policy.DoesTransactionFollowsPolicy(txByNewActivated));
        }
Beispiel #2
0
        public void DoesTransactionFollowsPolicyWithEmpty()
        {
            var adminPrivateKey = new PrivateKey();
            var adminAddress    = new Address(adminPrivateKey.PublicKey);
            IBlockPolicy <PolymorphicAction <ActionBase> > policy   = BlockPolicy.GetPolicy(10000);
            IRenderer <PolymorphicAction <ActionBase> >    renderer = BlockPolicy.GetRenderer();
            Block <PolymorphicAction <ActionBase> >        genesis  = MakeGenesisBlock(adminAddress, ImmutableHashSet <Address> .Empty);

            using var store = new DefaultStore(null);
            _ = new BlockChain <PolymorphicAction <ActionBase> >(
                policy,
                store,
                store,
                genesis,
                renderers: new[] { renderer }
                );
            Transaction <PolymorphicAction <ActionBase> > tx = Transaction <PolymorphicAction <ActionBase> > .Create(
                0,
                new PrivateKey(),
                genesis.Hash,
                new PolymorphicAction <ActionBase>[] { });

            Assert.True(policy.DoesTransactionFollowsPolicy(tx));
        }