Beispiel #1
0
        public void Rehearsal()
        {
            var action = new DailyReward4
            {
                avatarAddress = _avatarAddress,
            };

            var nextState = action.Execute(new ActionContext
            {
                BlockIndex     = 0,
                PreviousStates = new State(),
                Random         = new TestRandom(),
                Rehearsal      = true,
                Signer         = _agentAddress,
            });

            var updatedAddresses = new List <Address>()
            {
                _avatarAddress,
                _avatarAddress.Derive(LegacyInventoryKey),
                _avatarAddress.Derive(LegacyWorldInformationKey),
                _avatarAddress.Derive(LegacyQuestListKey),
            };

            Assert.Equal(updatedAddresses.ToImmutableHashSet(), nextState.UpdatedAddresses);
        }
Beispiel #2
0
        public void ExecuteThrowFailedLoadStateException()
        {
            var action = new DailyReward4
            {
                avatarAddress = _avatarAddress,
            };

            Assert.Throws <FailedLoadStateException>(() => action.Execute(new ActionContext()
            {
                PreviousStates = new State(),
                Signer         = _agentAddress,
                BlockIndex     = 0,
            })
                                                     );
        }
Beispiel #3
0
        public void Execute(bool backward)
        {
            var dailyRewardAction = new DailyReward4
            {
                avatarAddress = _avatarAddress,
            };

            if (!backward)
            {
                AvatarState avatarState = _initialState.GetAvatarState(_avatarAddress);
                _initialState = _initialState
                                .SetState(_avatarAddress.Derive(LegacyInventoryKey), avatarState.inventory.Serialize())
                                .SetState(_avatarAddress.Derive(LegacyWorldInformationKey), avatarState.worldInformation.Serialize())
                                .SetState(_avatarAddress.Derive(LegacyQuestListKey), avatarState.questList.Serialize())
                                .SetState(_avatarAddress, avatarState.SerializeV2());
            }

            var nextState = dailyRewardAction.Execute(new ActionContext
            {
                BlockIndex     = 0,
                PreviousStates = _initialState,
                Random         = new TestRandom(),
                Rehearsal      = false,
                Signer         = _agentAddress,
            });

            var gameConfigState = nextState.GetGameConfigState();
            var nextAvatarState = nextState.GetAvatarStateV2(_avatarAddress);

            Assert.Equal(gameConfigState.ActionPointMax, nextAvatarState.actionPoint);
            Assert.Single(nextAvatarState.mailBox);
            var mail       = nextAvatarState.mailBox.First();
            var rewardMail = mail as DailyRewardMail;

            Assert.NotNull(rewardMail);
            var rewardResult = rewardMail.attachment as DailyReward2.DailyRewardResult;

            Assert.NotNull(rewardResult);
            Assert.Single(rewardResult.materials);
            var material = rewardResult.materials.First();

            Assert.Equal(400000, material.Key.Id);
            Assert.Equal(10, material.Value);
        }