public void Execute() { var action = new CreateAvatar0() { avatarAddress = _avatarAddress, index = 0, hair = 0, ear = 0, lens = 0, tail = 0, name = "test", }; var gold = new GoldCurrencyState(new Currency("NCG", 2, minter: null)); var ranking = new RankingState0(); for (var i = 0; i < RankingState0.RankingMapCapacity; i++) { ranking.RankingMap[RankingState0.Derive(i)] = new HashSet <Address>().ToImmutableHashSet(); } var sheets = TableSheetsImporter.ImportSheets(); var state = new State() .SetState(GoldCurrencyState.Address, gold.Serialize()) .SetState( Addresses.GoldDistribution, GoldDistributionTest.Fixture.Select(v => v.Serialize()).Serialize() ) .SetState( Addresses.GameConfig, new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize() ) .SetState(Addresses.Ranking, ranking.Serialize()) .MintAsset(GoldCurrencyState.Address, gold.Currency * 100000000000); foreach (var(key, value) in sheets) { state = state.SetState(Addresses.TableSheet.Derive(key), value.Serialize()); } var nextState = action.Execute(new ActionContext() { PreviousStates = state, Signer = _agentAddress, BlockIndex = 0, }); Assert.Equal( 0, nextState.GetBalance(default, gold.Currency).MajorUnit
public InitializeStates( RankingState0 rankingState, ShopState shopState, Dictionary <string, string> tableSheets, GameConfigState gameConfigState, RedeemCodeState redeemCodeState, AdminState adminAddressState, ActivatedAccountsState activatedAccountsState, GoldCurrencyState goldCurrencyState, GoldDistribution[] goldDistributions, PendingActivationState[] pendingActivationStates, AuthorizedMinersState authorizedMinersState = null, CreditsState creditsState = null) { Ranking = (Bencodex.Types.Dictionary)rankingState.Serialize(); Shop = (Bencodex.Types.Dictionary)shopState.Serialize(); TableSheets = tableSheets; GameConfig = (Bencodex.Types.Dictionary)gameConfigState.Serialize(); RedeemCode = (Bencodex.Types.Dictionary)redeemCodeState.Serialize(); AdminAddress = (Bencodex.Types.Dictionary)adminAddressState.Serialize(); ActivatedAccounts = (Bencodex.Types.Dictionary)activatedAccountsState.Serialize(); GoldCurrency = (Bencodex.Types.Dictionary)goldCurrencyState.Serialize(); GoldDistributions = new Bencodex.Types.List( goldDistributions.Select(d => d.Serialize()).Cast <Bencodex.Types.IValue>() ); PendingActivations = new Bencodex.Types.List(pendingActivationStates.Select(p => p.Serialize())); if (!(authorizedMinersState is null)) { AuthorizedMiners = (Bencodex.Types.Dictionary)authorizedMinersState.Serialize(); } if (!(creditsState is null)) { Credits = (Bencodex.Types.Dictionary)creditsState.Serialize(); } }
public override IAccountStateDelta Execute(IActionContext context) { IActionContext ctx = context; var states = ctx.PreviousStates; var weeklyArenaState = new WeeklyArenaState(0); var rankingState = new RankingState0(Ranking); if (ctx.Rehearsal) { states = states.SetState(RankingState0.Address, MarkChanged); states = states.SetState(ShopState.Address, MarkChanged); #pragma warning disable LAA1002 states = TableSheets .Aggregate(states, (current, pair) => current.SetState(Addresses.TableSheet.Derive(pair.Key), MarkChanged)); states = rankingState.RankingMap .Aggregate(states, (current, pair) => current.SetState(pair.Key, MarkChanged)); #pragma warning restore LAA1002 states = states.SetState(weeklyArenaState.address, MarkChanged); states = states.SetState(GameConfigState.Address, MarkChanged); states = states.SetState(RedeemCodeState.Address, MarkChanged); states = states.SetState(AdminState.Address, MarkChanged); states = states.SetState(ActivatedAccountsState.Address, MarkChanged); states = states.SetState(GoldCurrencyState.Address, MarkChanged); states = states.SetState(Addresses.GoldDistribution, MarkChanged); foreach (var rawPending in PendingActivations) { states = states.SetState( new PendingActivationState((Bencodex.Types.Dictionary)rawPending).address, MarkChanged ); } states = states.SetState(AuthorizedMinersState.Address, MarkChanged); states = states.SetState(CreditsState.Address, MarkChanged); return(states); } if (ctx.BlockIndex != 0) { return(states); } #pragma warning disable LAA1002 states = TableSheets .Aggregate(states, (current, pair) => current.SetState(Addresses.TableSheet.Derive(pair.Key), pair.Value.Serialize())); states = rankingState.RankingMap .Aggregate(states, (current, pair) => current.SetState(pair.Key, new RankingMapState(pair.Key).Serialize())); #pragma warning restore LAA1002 states = states .SetState(weeklyArenaState.address, weeklyArenaState.Serialize()) .SetState(RankingState0.Address, Ranking) .SetState(ShopState.Address, Shop) .SetState(GameConfigState.Address, GameConfig) .SetState(RedeemCodeState.Address, RedeemCode) .SetState(AdminState.Address, AdminAddress) .SetState(ActivatedAccountsState.Address, ActivatedAccounts) .SetState(GoldCurrencyState.Address, GoldCurrency) .SetState(Addresses.GoldDistribution, GoldDistributions); if (!(AuthorizedMiners is null)) { states = states.SetState( AuthorizedMinersState.Address, AuthorizedMiners ); } foreach (var rawPending in PendingActivations) { states = states.SetState( new PendingActivationState((Bencodex.Types.Dictionary)rawPending).address, rawPending ); } if (!(Credits is null)) { states = states.SetState(CreditsState.Address, Credits); } var currency = new GoldCurrencyState(GoldCurrency).Currency; states = states.MintAsset(GoldCurrencyState.Address, currency * 1000000000); return(states); }