Skip to content

Commit 2d93256

Browse files
committed
Check recipient is stake address
1 parent 0e6e399 commit 2d93256

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

.Lib9c.Tests/Action/TransferAssetsTest.cs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ namespace Lib9c.Tests.Action
1414
using Nekoyume.Action;
1515
using Nekoyume.Helper;
1616
using Nekoyume.Model;
17+
using Nekoyume.Model.Stake;
1718
using Nekoyume.Model.State;
19+
using Nekoyume.TableData;
1820
using Xunit;
1921

2022
public class TransferAssetsTest
@@ -271,7 +273,7 @@ public void PlainValue(string memo)
271273

272274
var recipients = (List)values["recipients"];
273275
var info = (List)recipients[0];
274-
Assert.Equal((Text)"transfer_assets2", plainValue["type_id"]);
276+
Assert.Equal((Text)"transfer_assets3", plainValue["type_id"]);
275277
Assert.Equal(_sender, values["sender"].ToAddress());
276278
Assert.Equal(_recipient, info[0].ToAddress());
277279
Assert.Equal(_currency * 100, info[1].ToFungibleAssetValue());
@@ -398,5 +400,80 @@ public void Execute_Throw_InvalidTransferCurrencyException()
398400
BlockIndex = TransferAsset3.CrystalTransferringRestrictionStartIndex,
399401
}));
400402
}
403+
404+
[Fact]
405+
public void Execute_Throw_ArgumentException()
406+
{
407+
var baseState = new MockStateDelta(
408+
MockState.Empty
409+
.SetBalance(_sender, _currency * 1000));
410+
var action = new TransferAssets(
411+
sender: _sender,
412+
new List<(Address, FungibleAssetValue)>
413+
{
414+
(StakeState.DeriveAddress(_recipient), _currency * 100),
415+
(_recipient2, _currency * 100),
416+
}
417+
);
418+
// 스테이킹 주소에 송금하려고 하면 실패합니다.
419+
Assert.Throws<ArgumentException>("recipient", () => action.Execute(new ActionContext()
420+
{
421+
PreviousState = baseState
422+
.SetState(
423+
StakeState.DeriveAddress(_recipient),
424+
new StakeState(StakeState.DeriveAddress(_recipient), 0).SerializeV2()),
425+
Signer = _sender,
426+
Rehearsal = false,
427+
BlockIndex = 1,
428+
}));
429+
Assert.Throws<ArgumentException>("recipient", () => action.Execute(new ActionContext()
430+
{
431+
PreviousState = baseState
432+
.SetState(
433+
StakeState.DeriveAddress(_recipient),
434+
new StakeStateV2(
435+
new Contract(
436+
"StakeRegularFixedRewardSheet_V1",
437+
"StakeRegularRewardSheet_V1",
438+
50400,
439+
201600),
440+
0).Serialize()),
441+
Signer = _sender,
442+
Rehearsal = false,
443+
BlockIndex = 1,
444+
}));
445+
Assert.Throws<ArgumentException>("recipient", () => action.Execute(new ActionContext()
446+
{
447+
PreviousState = baseState
448+
.SetState(
449+
StakeState.DeriveAddress(_recipient),
450+
new MonsterCollectionState(
451+
MonsterCollectionState.DeriveAddress(_sender, 0),
452+
1,
453+
0)
454+
.Serialize()),
455+
Signer = _sender,
456+
Rehearsal = false,
457+
BlockIndex = 1,
458+
}));
459+
var monsterCollectionRewardSheet = new MonsterCollectionRewardSheet();
460+
monsterCollectionRewardSheet.Set(
461+
"level,required_gold,reward_id\n1,500,1\n2,1800,2\n3,7200,3\n4,54000,4\n5,270000,5\n6,480000,6\n7,1500000,7\n");
462+
Assert.Throws<ArgumentException>("recipient", () => action.Execute(new ActionContext()
463+
{
464+
PreviousState = baseState
465+
.SetState(
466+
StakeState.DeriveAddress(_recipient),
467+
new MonsterCollectionState0(
468+
MonsterCollectionState.DeriveAddress(_sender, 0),
469+
1,
470+
0,
471+
monsterCollectionRewardSheet)
472+
.Serialize()),
473+
Signer = _sender,
474+
Rehearsal = false,
475+
BlockIndex = 1,
476+
}));
477+
}
401478
}
402479
}

Lib9c/Action/TransferAssets.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Nekoyume.Action
2323
[ActionType(TypeIdentifier)]
2424
public class TransferAssets : ActionBase, ISerializable, ITransferAssets, ITransferAssetsV1
2525
{
26-
public const string TypeIdentifier = "transfer_assets2";
26+
public const string TypeIdentifier = "transfer_assets3";
2727
public const int RecipientsCapacity = 100;
2828
private const int MemoMaxLength = 80;
2929

@@ -160,6 +160,7 @@ private IAccount Transfer(
160160
}
161161

162162
TransferAsset3.CheckCrystalSender(currency, blockIndex, Sender);
163+
TransferAsset.CheckRecipientIsStake(state, recipient);
163164
return state.TransferAsset(context, Sender, recipient, amount);
164165
}
165166
}

0 commit comments

Comments
 (0)