Skip to content

Commit

Permalink
Commit tests for mytoken contract.
Browse files Browse the repository at this point in the history
  • Loading branch information
eanzhao committed Dec 10, 2024
1 parent 42fb6a1 commit 22f9d8d
Show file tree
Hide file tree
Showing 6 changed files with 687 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ private void TerminateV1(int beneficiaryPtr)

private void Terminate(int beneficiaryPtr)
{
RuntimeLogs.Add("Terminate");
var beneficiary = ReadSandboxMemory(beneficiaryPtr, AElfConstants.AddressHashLength);
var amount = State.TokenContract.GetBalance.Call(new GetBalanceInput
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AElf.Runtime.WebAssembly.Types;
using AElf.Types;
using Google.Protobuf;
using Nethereum.ABI;
using Scale;
using Shouldly;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Threading.Tasks;
using AElf.Types;
using Scale;
using Shouldly;
using Xunit.Abstractions;

namespace AElf.Contracts.SolidityContract;

public class DestructTests : SolidityContractTestBase
{
private readonly ITestOutputHelper _outputHelper;

public DestructTests(ITestOutputHelper outputHelper) : base(outputHelper)
{
_outputHelper = outputHelper;
ContractPath = "contracts/destruct.contract";
}

[Fact]
public async Task HelloTest()
{
var contractAddress = await DeployContractAsync();
var txResult = await ExecuteTransactionAsync(contractAddress, "hello");
txResult.Status.ShouldBe(TransactionResultStatus.Mined);
StringType.From(txResult.ReturnValue.ToByteArray()).ToString().ShouldBe("Hello");
}

[Fact(Skip = "Not support selfdestruct yet.")]
public async Task SelfterminateTest()
{
var contractAddress = await DeployContractAsync();
var txResult = await ExecuteTransactionAsync(contractAddress, "selfterminate");
txResult.Status.ShouldBe(TransactionResultStatus.Mined);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Threading.Tasks;
using Scale;
using Shouldly;
using Xunit.Abstractions;

namespace AElf.Contracts.SolidityContract;

public class MyTokenTests : SolidityContractTestBase
{
private readonly ITestOutputHelper _outputHelper;

public MyTokenTests(ITestOutputHelper outputHelper) : base(outputHelper)
{
_outputHelper = outputHelper;
ContractPath = "contracts/mytoken.contract";
}

[Fact]
public async Task MyTokenTest()
{
var contractAddress = await DeployContractAsync();

{
var txResult = await ExecuteTransactionAsync(contractAddress, "test",
TupleType<AddressType, BoolType>.GetByteStringFrom(
AddressType.From(DefaultSender.ToByteArray()),
BoolType.From(true)
));

AddressType.From(txResult.ReturnValue.ToByteArray()).Value.ShouldBe(DefaultSender);
}

{
var txResult = await ExecuteTransactionAsync(contractAddress, "test",
TupleType<AddressType, BoolType>.GetByteStringFrom(
AddressType.From(DefaultSender.ToByteArray()),
BoolType.From(false)
));

AddressType.From(txResult.ReturnValue.ToByteArray()).Value.ShouldBe(DefaultSender);
}
}
}
299 changes: 299 additions & 0 deletions test/AElf.Contracts.SolidityContract.Tests/contracts/destruct.contract

Large diffs are not rendered by default.

309 changes: 309 additions & 0 deletions test/AElf.Contracts.SolidityContract.Tests/contracts/mytoken.contract

Large diffs are not rendered by default.

0 comments on commit 22f9d8d

Please sign in to comment.