Skip to content

Commit

Permalink
apply code sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-doobu committed Oct 22, 2024
1 parent 687028e commit bbf4ec8
Show file tree
Hide file tree
Showing 175 changed files with 6,030 additions and 4,796 deletions.
6 changes: 4 additions & 2 deletions .Lib9c.Tests/Action/AccountStateDeltaExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ public void SetWorldBossKillReward(int level, int expectedRune, int expectedCrys
);
var bossId = bossState.Id;
var runeWeightSheet = new RuneWeightSheet();
runeWeightSheet.Set($@"id,boss_id,rank,rune_id,weight
runeWeightSheet.Set(
$@"id,boss_id,rank,rune_id,weight
1,{bossId},0,10001,100
");
var killRewardSheet = new WorldBossKillRewardSheet();
killRewardSheet.Set($@"id,boss_id,rank,rune_min,rune_max,crystal,circle
killRewardSheet.Set(
$@"id,boss_id,rank,rune_min,rune_max,crystal,circle
1,{bossId},0,1,1,100,0
");

Expand Down
31 changes: 17 additions & 14 deletions .Lib9c.Tests/Action/ActionContextExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,23 @@ public void IsMainNet(GoldCurrencyState goldCurrencyState, bool expected)
[Fact]
public void Since()
{
Assert.True(new ActionContext
{
BlockIndex = 1001,
}.Since(1000));

Assert.True(new ActionContext
{
BlockIndex = 0,
}.Since(0));

Assert.False(new ActionContext
{
BlockIndex = 0,
}.Since(1));
Assert.True(
new ActionContext
{
BlockIndex = 1001,
}.Since(1000));

Assert.True(
new ActionContext
{
BlockIndex = 0,
}.Since(0));

Assert.False(
new ActionContext
{
BlockIndex = 0,
}.Since(1));
}
}
}
10 changes: 6 additions & 4 deletions .Lib9c.Tests/Action/ActionEvaluationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,12 @@ private ActionBase GetAction(Type type)
AgentAddresses = new[] { (new PrivateKey().Address, new PrivateKey().Address), },
Mead = 4,
},
TransferAssets _ => new TransferAssets(_sender, new List<(Address, FungibleAssetValue)>
{
(_signer, 1 * _currency),
}),
TransferAssets _ => new TransferAssets(
_sender,
new List<(Address, FungibleAssetValue)>
{
(_signer, 1 * _currency),
}),
RuneSummon _ => new RuneSummon
{
AvatarAddress = _sender,
Expand Down
47 changes: 26 additions & 21 deletions .Lib9c.Tests/Action/ActivateCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ public void Execute()
{
var item = ItemFactory.CreateItem(itemRow, random);
avatarState.inventory.AddItem(item, material.Count);
materials.Add(new FungibleCollectionMaterial
{
ItemId = item.Id,
ItemCount = material.Count,
});
materials.Add(
new FungibleCollectionMaterial
{
ItemId = item.Id,
ItemCount = material.Count,
});
}
else
{
Expand All @@ -92,23 +93,25 @@ public void Execute()
avatarState.inventory.AddItem(item);
if (item.ItemType != ItemType.Consumable)
{
materials.Add(new NonFungibleCollectionMaterial
{
ItemId = item.Id,
NonFungibleId = nonFungibleId,
SkillContains = material.SkillContains,
});
materials.Add(
new NonFungibleCollectionMaterial
{
ItemId = item.Id,
NonFungibleId = nonFungibleId,
SkillContains = material.SkillContains,
});
}
else
{
// Add consumable material only one.
if (i == 0)
{
materials.Add(new FungibleCollectionMaterial
{
ItemId = item.Id,
ItemCount = material.Count,
});
materials.Add(
new FungibleCollectionMaterial
{
ItemId = item.Id,
ItemCount = material.Count,
});
}
}
}
Expand Down Expand Up @@ -137,11 +140,13 @@ public void Execute()
var nextAvatarState = nextState.GetAvatarState(_avatarAddress);
Assert.Empty(nextAvatarState.inventory.Items);

Assert.Throws<AlreadyActivatedException>(() => activateCollection.Execute(new ActionContext
{
PreviousState = nextState,
Signer = _agentAddress,
}));
Assert.Throws<AlreadyActivatedException>(
() => activateCollection.Execute(
new ActionContext
{
PreviousState = nextState,
Signer = _agentAddress,
}));
}
}
}
75 changes: 40 additions & 35 deletions .Lib9c.Tests/Action/AddRedeemCodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,32 @@ public void CheckPermission()
redeemCsv = "New Value",
};

var exc1 = Assert.Throws<PolicyExpiredException>(() =>
{
action.Execute(
new ActionContext
{
BlockIndex = 101,
PreviousState = state,
Signer = adminAddress,
}
);
});
var exc1 = Assert.Throws<PolicyExpiredException>(
() =>
{
action.Execute(
new ActionContext
{
BlockIndex = 101,
PreviousState = state,
Signer = adminAddress,
}
);
});
Assert.Equal(101, exc1.BlockIndex);

var exc2 = Assert.Throws<PermissionDeniedException>(() =>
{
action.Execute(
new ActionContext
{
BlockIndex = 5,
PreviousState = state,
Signer = new Address("019101FEec7ed4f918D396827E1277DEda1e20D4"),
}
);
});
var exc2 = Assert.Throws<PermissionDeniedException>(
() =>
{
action.Execute(
new ActionContext
{
BlockIndex = 5,
PreviousState = state,
Signer = new Address("019101FEec7ed4f918D396827E1277DEda1e20D4"),
}
);
});
Assert.Equal(new Address("019101FEec7ed4f918D396827E1277DEda1e20D4"), exc2.Signer);
}

Expand All @@ -64,14 +66,15 @@ public void Execute()
redeemCsv = csv,
};

var nextState = action.Execute(new ActionContext
{
Signer = adminAddress,
BlockIndex = 0,
PreviousState = new World(MockUtil.MockModernWorldState)
.SetLegacyState(Addresses.Admin, adminState.Serialize())
.SetLegacyState(Addresses.RedeemCode, new RedeemCodeState(new RedeemCodeListSheet()).Serialize()),
});
var nextState = action.Execute(
new ActionContext
{
Signer = adminAddress,
BlockIndex = 0,
PreviousState = new World(MockUtil.MockModernWorldState)
.SetLegacyState(Addresses.Admin, adminState.Serialize())
.SetLegacyState(Addresses.RedeemCode, new RedeemCodeState(new RedeemCodeListSheet()).Serialize()),
});

var sheet = new RedeemCodeListSheet();
sheet.Set(csv);
Expand All @@ -98,11 +101,13 @@ public void ExecuteThrowSheetRowValidateException()
redeemCsv = csv,
};

Assert.Throws<SheetRowValidateException>(() => action.Execute(new ActionContext
{
BlockIndex = 0,
PreviousState = state,
})
Assert.Throws<SheetRowValidateException>(
() => action.Execute(
new ActionContext
{
BlockIndex = 0,
PreviousState = state,
})
);
}
}
Expand Down
Loading

0 comments on commit bbf4ec8

Please sign in to comment.