Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support two levels of smart contract inheritance #1028

Open
wants to merge 2 commits into
base: release/1.3.4.0
Choose a base branch
from
Open
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 @@ -128,5 +128,34 @@ public Test(ISmartContractState state)
Assert.NotNull(type);
Assert.Equal("Test", type.Name);
}

[Fact]
public void GetDeployedType_TwoLevelsOfInheritance_CorrectType()
{
var code = @"
using Stratis.SmartContracts;

public class BaseType : SmartContract
{
public BaseType(ISmartContractState state) : base(state) {}
}

[Deploy]
public class InheritedType : BaseType
{
public InheritedType(ISmartContractState state) : base(state) {}
}
";
var compilation = ContractCompiler.Compile(code);

var assemblyLoadResult = this.loader.Load((ContractByteCode)compilation.Compilation);

var contractAssembly = assemblyLoadResult.Value;

var type = contractAssembly.DeployedType;

Assert.NotNull(type);
Assert.Equal("InheritedType", type.Name);
}
}
}
5 changes: 2 additions & 3 deletions src/Stratis.SmartContracts.CLR/Loader/ContractAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ private Type GetDeployedType()
x.CustomAttributes.Any(y => y.AttributeType == typeof(DeployAttribute)));
}

public static bool IsContractType(Type typeDefinition)
private static bool IsContractType(Type typeDefinition)
{
return typeDefinition.IsClass &&
!typeDefinition.IsAbstract &&
typeDefinition.BaseType != null &&
typeDefinition.BaseType == typeof(SmartContract);
typeDefinition.IsSubclassOf(typeof(SmartContract));
}

private Type GetObserverType()
Expand Down