Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
parts: 3
n: 2
codecoverage: true
# - template: templates/build-template-macos.yml
# parameters:
# parts: 3
# n: 3
# codecoverage: true
- template: templates/build-template-macos.yml
parameters:
parts: 3
n: 3
codecoverage: true

6 changes: 4 additions & 2 deletions contract/AElf.Contracts.TokenHolder/TokenHolderContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public partial class TokenHolderContract : TokenHolderContractImplContainer.Toke
{
public override Empty CreateScheme(CreateTokenHolderProfitSchemeInput input)
{
Assert(State.TokenHolderProfitSchemes[Context.Sender] == null, "Token holder profit scheme already exists.");

if (State.ProfitContract.Value == null)
State.ProfitContract.Value =
Context.GetContractAddressByName(SmartContractConstants.ProfitContractSystemName);
Expand Down Expand Up @@ -52,7 +54,7 @@ public override Empty AddBeneficiary(AddTokenHolderBeneficiaryInput input)
SchemeId = scheme.SchemeId,
Beneficiary = input.Beneficiary
});
shares.Add(detail.Details.Single().Shares);
shares = shares.Add(detail.Details.Single().Shares);
}

State.ProfitContract.AddBeneficiary.Send(new AddBeneficiaryInput
Expand Down Expand Up @@ -295,6 +297,6 @@ private void UpdateTokenHolderProfitScheme(ref TokenHolderProfitScheme scheme, A
var originScheme = State.ProfitContract.GetScheme.Call(originSchemeId);
scheme.SchemeId = originScheme.SchemeId;
scheme.Period = originScheme.CurrentPeriod;
State.TokenHolderProfitSchemes[Context.Sender] = scheme;
State.TokenHolderProfitSchemes[manager] = scheme;
}
}
1 change: 0 additions & 1 deletion nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
<add key="aelf" value="https://www.myget.org/F/aelf-project-dev/api/v3/index.json" protocolVersion="3"/>
<add key="Nuget Test" value="https://int.nugettest.org/api/v2" />
<add key="nexus" value="https://nexus-poc.test.aelf.dev/repository/nuget-group/index.json" protocolVersion="3" />
</packageSources>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class TokenHolderContractTestBase : ContractTestBase<TokenHolderContractT
protected Address Receiver => Accounts[1].Address;

protected List<ECKeyPair> UserKeyPairs => Accounts.Skip(2).Take(3).Select(a => a.KeyPair).ToList();

protected ECKeyPair OtherKeyPair => Accounts[2].KeyPair;
protected Address Other => Accounts[2].Address;

protected List<Address> UserAddresses =>
UserKeyPairs.Select(k => Address.FromPublicKey(k.PublicKey)).ToList();
Expand All @@ -58,6 +61,8 @@ public class TokenHolderContractTestBase : ContractTestBase<TokenHolderContractT
internal ParliamentContractImplContainer.ParliamentContractImplStub ParliamentContractStub { get; set; }

internal TokenHolderContractImplContainer.TokenHolderContractImplStub TokenHolderContractStub { get; set; }

internal TokenHolderContractImplContainer.TokenHolderContractImplStub OtherTokenHolderContractStub { get; set; }

internal DAppContainer.DAppStub DAppContractStub { get; set; }

Expand Down Expand Up @@ -90,6 +95,8 @@ protected void InitializeContracts()
new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList()
})).Output;
TokenHolderContractStub = GetTokenHolderContractTester(StarterKeyPair);

OtherTokenHolderContractStub = GetTokenHolderContractTester(OtherKeyPair);

//deploy parliament auth contract
ParliamentContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
Expand Down
65 changes: 63 additions & 2 deletions test/AElf.Contracts.TokenHolder.Tests/TokenHolderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,71 @@ await TokenHolderContractStub.ContributeProfits.SendAsync(new ContributeProfitsI

{
var tokenHolderProfitScheme = await TokenHolderContractStub.GetScheme.CallAsync(Starter);
tokenHolderProfitScheme.SchemeId.ShouldNotBeNull();
var schemeId = tokenHolderProfitScheme.SchemeId;
schemeId.ShouldNotBeNull();

var result = await TokenHolderContractStub.CreateScheme.SendWithExceptionAsync(new CreateTokenHolderProfitSchemeInput
{
Symbol = "AUG"
});

result.TransactionResult.Status.ShouldBe(TransactionResultStatus.Failed);
result.TransactionResult.Error.ShouldContain("Token holder profit scheme already exists");
}
}

[Fact]
public async Task AddBeneficiaryWithWrongManagerTest()
{
var symbol = "AUG";
var totalSupply = 10000000;
var transferAmount = 1000;
await StarterCreateIssueAndApproveTokenAsync(symbol, totalSupply, totalSupply);
await TokenHolderContractStub.CreateScheme.SendAsync(new CreateTokenHolderProfitSchemeInput
{
Symbol = symbol
});

await TokenContractStub.Transfer.SendAsync(new TransferInput
{
To = Other,
Amount = transferAmount,
Symbol = symbol
});

await OtherTokenHolderContractStub.RegisterForProfits.SendAsync(new RegisterForProfitsInput
{
SchemeManager = Starter,
Amount = 10
});

var tokenHolderProfitScheme = await TokenHolderContractStub.GetScheme.CallAsync(Other);
tokenHolderProfitScheme.SchemeId.ShouldBeNull();
tokenHolderProfitScheme.Symbol.ShouldBeEmpty();

tokenHolderProfitScheme = await TokenHolderContractStub.GetScheme.CallAsync(Starter);

var scheme = await ProfitContractStub.GetScheme.CallAsync(tokenHolderProfitScheme.SchemeId);
scheme.TotalShares.ShouldBe(10);

var result = await OtherTokenHolderContractStub.AddBeneficiary.SendWithExceptionAsync(new AddTokenHolderBeneficiaryInput
{
Beneficiary = Other,
Shares = 100
});
result.TransactionResult.Status.ShouldBe(TransactionResultStatus.Failed);
result.TransactionResult.Error.ShouldContain("Token holder profit scheme not found");

await TokenHolderContractStub.AddBeneficiary.SendAsync(new AddTokenHolderBeneficiaryInput
{
Beneficiary = Other,
Shares = 100
});

scheme = await ProfitContractStub.GetScheme.CallAsync(tokenHolderProfitScheme.SchemeId);
scheme.TotalShares.ShouldBe(110);
}

[Fact]
public async Task ContributeProfitsTest()
{
Expand Down Expand Up @@ -130,7 +191,7 @@ await TokenHolderContractStub.AddBeneficiary.SendAsync(new AddTokenHolderBenefic

{
var originScheme = await ProfitContractStub.GetScheme.CallAsync(tokenHolderProfitScheme.SchemeId);
originScheme.TotalShares.ShouldBe(newShare);
originScheme.TotalShares.ShouldBe(newShare + 1);
}
}

Expand Down
Loading