コード例 #1
0
        public void Execute(int prevLevel, int collectionLevel, long blockIndex)
        {
            Address collectionAddress = MonsterCollectionState0.DeriveAddress(_signer, 0);
            List <MonsterCollectionRewardSheet.RewardInfo> rewardInfos = _tableSheets.MonsterCollectionRewardSheet[prevLevel].Rewards;
            MonsterCollectionState0 monsterCollectionState             = new MonsterCollectionState0(collectionAddress, prevLevel, 0, _tableSheets.MonsterCollectionRewardSheet);
            Currency           currency = _state.GetGoldCurrency();
            FungibleAssetValue balance  = 0 * currency;

            foreach (var row in _tableSheets.MonsterCollectionSheet)
            {
                if (collectionLevel < row.Level && row.Level <= prevLevel)
                {
                    balance += row.RequiredGold * currency;
                }
            }

            Assert.All(monsterCollectionState.RewardLevelMap, kv => Assert.Equal(rewardInfos, kv.Value));

            _state = _state
                     .SetState(collectionAddress, monsterCollectionState.Serialize())
                     .MintAsset(collectionAddress, balance);

            CancelMonsterCollect action = new CancelMonsterCollect
            {
                collectRound = 0,
                level        = collectionLevel,
            };

            IAccountStateDelta nextState = action.Execute(new ActionContext
            {
                PreviousStates = _state,
                Signer         = _signer,
                BlockIndex     = blockIndex,
            });

            MonsterCollectionState0 nextMonsterCollectionState = new MonsterCollectionState0((Dictionary)nextState.GetState(collectionAddress));

            Assert.Equal(collectionLevel, nextMonsterCollectionState.Level);
            Assert.Equal(0 * currency, nextState.GetBalance(collectionAddress, currency));
            Assert.Equal(balance, nextState.GetBalance(_signer, currency));

            long rewardLevel = nextMonsterCollectionState.GetRewardLevel(blockIndex);
            List <MonsterCollectionRewardSheet.RewardInfo> nextRewardInfos = _tableSheets.MonsterCollectionRewardSheet[collectionLevel].Rewards;

            for (long i = rewardLevel; i < 4; i++)
            {
                Assert.Equal(nextRewardInfos, nextMonsterCollectionState.RewardLevelMap[i + 1]);
            }
        }
コード例 #2
0
        public void Execute_Throw_FailedLoadStateException_AgentState()
        {
            CancelMonsterCollect action = new CancelMonsterCollect
            {
                level        = 0,
                collectRound = 0,
            };

            Assert.Throws <FailedLoadStateException>(() => action.Execute(new ActionContext
            {
                PreviousStates = _state,
                Signer         = new PrivateKey().ToAddress(),
                BlockIndex     = 0,
            })
                                                     );
        }
コード例 #3
0
        public void Execute_Throw_InvalidLevelException(int prevLevel, int level)
        {
            Address collectionAddress = MonsterCollectionState0.DeriveAddress(_signer, 0);
            MonsterCollectionState0 monsterCollectionState = new MonsterCollectionState0(collectionAddress, prevLevel, 0, _tableSheets.MonsterCollectionRewardSheet);

            _state = _state.SetState(collectionAddress, monsterCollectionState.Serialize());

            CancelMonsterCollect action = new CancelMonsterCollect
            {
                level        = level,
                collectRound = 0,
            };

            Assert.Throws <InvalidLevelException>(() => action.Execute(new ActionContext
            {
                PreviousStates = _state,
                Signer         = _signer,
                BlockIndex     = 0,
            })
                                                  );
        }