Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Hash OwnCodeHash()

public bool CallerIsOrigin()
{
throw new NotImplementedException();
return Caller.CompareTo(ContractAddress) == 1;
}

public bool CallerIsRoot()
Expand Down
28 changes: 28 additions & 0 deletions test/AElf.Contracts.SolidityContract.Tests/CallerIsOriginTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AElf.Types;
using Google.Protobuf;
using Nethereum.ABI;
using Nethereum.ABI.Decoders;
using Shouldly;

namespace AElf.Contracts.SolidityContract;

public class CallerIsOriginTest: SolidityContractTestBase
{
//TODO This is a WIP and needs further study
// [Fact] public async Task<Address> CallerIsOrigin()
// {
// const string solFilePath = "contracts/caller_is_origin.sol";
// var executionResult = await DeployWebAssemblyContractAsync(await File.ReadAllBytesAsync(solFilePath));
// var contractAddress = executionResult.Output;
// var tx = await GetTransactionAsync(DefaultSenderKeyPair, contractAddress, "caller_is_origin");
// var txResult = await TestTransactionExecutor.ExecuteAsync(tx);
// txResult.Status.ShouldBe(TransactionResultStatus.Mined);
// var decoder = new IntTypeDecoder();
// var result = decoder.DecodeLong(txResult.ReturnValue.Reverse().ToArray());
// result.ShouldBe(1);
// return contractAddress;
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pragma solidity ^0.8.0;

contract CallerIsOrigin {
function callerIsOrigin() public view returns (int) {
return caller_is_origin(msg.sender);
}
}