Skip to content
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