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

Remove ContractFeatures #390

Merged
merged 10 commits into from
Nov 13, 2020
Merged
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
10 changes: 1 addition & 9 deletions src/Neo.Compiler.MSIL/FuncExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Linq;
using System.Text;
using IApiInterface = scfx.Neo.SmartContract.Framework.IApiInterface;
using ContractFeatures = scfx.Neo.SmartContract.Framework.ContractFeatures;

namespace Neo.Compiler
{
Expand Down Expand Up @@ -212,21 +211,14 @@ public static string GenerateManifest(JObject abi, NeoModule module)
{
var sbABI = abi.ToString(false);

var features = module == null ? ContractFeatures.NoProperty : module.attributes
.Where(u => u.AttributeType.FullName == "Neo.SmartContract.Framework.FeaturesAttribute")
.Select(u => (ContractFeatures)u.ConstructorArguments.FirstOrDefault().Value)
.FirstOrDefault();

var extraAttributes = module == null ? Array.Empty<Mono.Collections.Generic.Collection<CustomAttributeArgument>>() : module.attributes.Where(u => u.AttributeType.FullName == "Neo.SmartContract.Framework.ManifestExtraAttribute").Select(attribute => attribute.ConstructorArguments).ToArray();
var supportedStandardsAttribute = module?.attributes.Where(u => u.AttributeType.FullName == "Neo.SmartContract.Framework.SupportedStandardsAttribute").Select(attribute => attribute.ConstructorArguments).FirstOrDefault();

var extra = BuildExtraAttributes(extraAttributes);
var supportedStandards = BuildSupportedStandards(supportedStandardsAttribute);
var storage = features.HasFlag(ContractFeatures.HasStorage).ToString().ToLowerInvariant();
var payable = features.HasFlag(ContractFeatures.Payable).ToString().ToLowerInvariant();

return
@"{""groups"":[],""features"":{""storage"":" + storage + @",""payable"":" + payable + @"},""abi"":" +
@"{""groups"":[],""abi"":" +
sbABI +
@",""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safemethods"":[],""supportedstandards"":" + supportedStandards + @",""extra"":" + extra + "}";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.4.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
<PackageReference Include="Neo" Version="3.0.0-CI01066" />
<PackageReference Include="Neo" Version="3.0.0-CI01068" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 0 additions & 13 deletions src/Neo.SmartContract.Framework/ContractFeatures.cs

This file was deleted.

22 changes: 0 additions & 22 deletions src/Neo.SmartContract.Framework/FeaturesAttribute.cs

This file was deleted.

1 change: 0 additions & 1 deletion templates/Template.CSharp/Contract1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace $safeprojectname$
[ManifestExtra("Author", "Neo")]
[ManifestExtra("Email", "dev@neo.org")]
[ManifestExtra("Description", "This is a contract example")]
[Features(ContractFeatures.HasStorage)]
public class Contract1 : SmartContract
{
//TODO: Replace it with your own address.
Expand Down
1 change: 0 additions & 1 deletion templates/Template.NEP5.CSharp/NEP5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Template.NEP5.CSharp
[ManifestExtra("Email", "dev@neo.org")]
[ManifestExtra("Description", "This is a NEP5 example")]
[SupportedStandards("NEP5", "NEP10")]
[Features(ContractFeatures.HasStorage | ContractFeatures.Payable)]
shargon marked this conversation as resolved.
Show resolved Hide resolved
public partial class NEP5 : SmartContract
{
#region Token Settings
Expand Down
6 changes: 0 additions & 6 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_NULL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ public void NullCollationAndCollation()
{
Script = testengine.EntryContext.Script,
Manifest = new ContractManifest()
{
Features = ContractFeatures.HasStorage
}
});

var result = _testengine.ExecuteTestCaseStandard("nullCollationAndCollation", "nes");
Expand All @@ -131,9 +128,6 @@ public void NullCollationAndCollation2()
{
Script = testengine.EntryContext.Script,
Manifest = new ContractManifest()
{
Features = ContractFeatures.HasStorage
}
});

var result = _testengine.ExecuteTestCaseStandard("nullCollationAndCollation2", "nes");
Expand Down
31 changes: 0 additions & 31 deletions tests/Neo.SmartContract.Framework.UnitTests/FeatureTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ public void GetContract()
Script = new byte[] { 0x01, 0x02, 0x03 },
Manifest = new Manifest.ContractManifest()
{
Features = Manifest.ContractFeatures.HasStorage,
SupportedStandards = new string[0],
Groups = new Manifest.ContractGroup[0],
Trusts = Manifest.WildcardContainer<UInt160>.Create(),
Expand Down Expand Up @@ -371,39 +370,6 @@ public void GetContract()
Assert.IsInstanceOfType(item, typeof(VM.Types.ByteString));
Assert.AreEqual(contract.Manifest.ToString(), item.GetString());

// Found + HasStorage

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("getContract", new VM.Types.ByteString(contract.ScriptHash.ToArray()), new VM.Types.ByteString(Utility.StrictUTF8.GetBytes("HasStorage")));
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.AreEqual(contract.HasStorage, item.GetBoolean());

// Found + IsPayable

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("getContract", new VM.Types.ByteString(contract.ScriptHash.ToArray()), new VM.Types.ByteString(Utility.StrictUTF8.GetBytes("IsPayable")));
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.AreEqual(contract.Payable, item.GetBoolean());

// Found + IsPayable

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("getContract", new VM.Types.ByteString(contract.ScriptHash.ToArray()), new VM.Types.ByteString(Utility.StrictUTF8.GetBytes("Script")));
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

item = result.Pop();
Assert.IsInstanceOfType(item, typeof(VM.Types.ByteString));
CollectionAssert.AreEqual(contract.Script, item.GetSpan().ToArray());

// Found + Uknown property

_engine.Reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,10 @@ public void Test_CreateCallDestroy()
var script = _engine.Build("./TestClasses/Contract_Create.cs");
var manifest = ContractManifest.FromJson(JObject.Parse(script.finalManifest));

// Check first

_engine.Reset();
var result = _engine.ExecuteTestCaseStandard("call", manifest.Hash.ToArray(), "oldContract", new Array());
Assert.AreEqual(VMState.FAULT, _engine.State);
Assert.AreEqual(0, result.Count);

// Create

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("create", script.finalNEF, manifest.ToJson().ToString());
var result = _engine.ExecuteTestCaseStandard("create", script.finalNEF, manifest.ToJson().ToString());
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

Expand All @@ -48,8 +41,6 @@ public void Test_CreateCallDestroy()
var itemArray = item as Array;
Assert.AreEqual(script.finalNEF, itemArray[0]); // Script
Assert.AreEqual(manifest.ToString(), itemArray[1].GetString()); // Manifest
Assert.AreEqual(false, itemArray[2]); // HasStorage
Assert.AreEqual(false, itemArray[3]); // Payable

// Call

Expand Down Expand Up @@ -88,21 +79,10 @@ public void Test_Update()
var scriptUpdate = _engine.Build("./TestClasses/Contract_Update.cs");
var manifestUpdate = ContractManifest.FromJson(JObject.Parse(scriptUpdate.finalManifest));

// Check first

_engine.Reset();
var result = _engine.ExecuteTestCaseStandard("call", manifest.Hash.ToArray(), "oldContract", new Array());
Assert.AreEqual(VMState.FAULT, _engine.State);
Assert.AreEqual(0, result.Count);

_engine.Reset();
_ = _engine.ExecuteTestCaseStandard("call", manifestUpdate.Hash.ToArray(), "newContract", new Array());
Assert.AreEqual(VMState.FAULT, _engine.State);

// Create

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("create", script.finalNEF, manifest.ToJson().ToString());
var result = _engine.ExecuteTestCaseStandard("create", script.finalNEF, manifest.ToJson().ToString());
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

Expand All @@ -111,8 +91,6 @@ public void Test_Update()
var itemArray = item as Array;
Assert.AreEqual(script.finalNEF, itemArray[0]); // Script
Assert.AreEqual(manifest.ToString(), itemArray[1].GetString()); // Manifest
Assert.AreEqual(false, itemArray[2]); // HasStorage
Assert.AreEqual(false, itemArray[3]); // Payable

// Call & Update

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void Test_GasLeft()

var item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Integer));
Assert.AreEqual(TestEngine.TestGas - 1200, item.GetInteger());
Assert.AreEqual(TestEngine.TestGas - 2000, item.GetInteger());
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Neo.Ledger;
using Neo.VM;
using System.Linq;
using ContractFeatures = scfx.Neo.SmartContract.Framework.ContractFeatures;

namespace Neo.SmartContract.Framework.UnitTests.Services.Neo
{
Expand All @@ -22,18 +21,10 @@ public void Init()

_engine = new TestEngine(snapshot: snapshot.Clone());
_engine.AddEntryScript("./TestClasses/Contract_StaticStorageMap.cs");
Assert.AreEqual(ContractFeatures.HasStorage, _engine.ScriptEntry.converterIL.outModule.attributes
.Where(u => u.AttributeType.Name == "FeaturesAttribute")
.Select(u => (ContractFeatures)u.ConstructorArguments.FirstOrDefault().Value)
.FirstOrDefault());

_engine.Snapshot.Contracts.Add(_engine.EntryScriptHash, new ContractState()
{
Script = _engine.EntryContext.Script,
Manifest = new Manifest.ContractManifest()
{
Features = Manifest.ContractFeatures.HasStorage
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Neo.VM.Types;
using System;
using System.Linq;
using ContractFeatures = scfx.Neo.SmartContract.Framework.ContractFeatures;

namespace Neo.SmartContract.Framework.UnitTests.Services.Neo
{
Expand Down Expand Up @@ -66,18 +65,10 @@ public void Init()

testengine = new TestEngine(snapshot: snapshot.Clone());
testengine.AddEntryScript("./TestClasses/Contract_Storage.cs");
Assert.AreEqual(ContractFeatures.HasStorage, testengine.ScriptEntry.converterIL.outModule.attributes
.Where(u => u.AttributeType.FullName == "Neo.SmartContract.Framework.FeaturesAttribute")
.Select(u => (ContractFeatures)u.ConstructorArguments.FirstOrDefault().Value)
.FirstOrDefault());

testengine.Snapshot.Contracts.Add(testengine.EntryScriptHash, new Ledger.ContractState()
{
Script = testengine.EntryContext.Script,
Manifest = new Manifest.ContractManifest()
{
Features = Manifest.ContractFeatures.HasStorage
}
});
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Neo.Compiler.MSIL.TestClasses
{
[Features(ContractFeatures.HasStorage)]
class Contract_StaticStorageMap : SmartContract.Framework.SmartContract
{
private static StorageMap Data = Storage.CurrentContext.CreateMap("data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Neo.Compiler.MSIL.TestClasses
{
[Features(ContractFeatures.HasStorage)]
class Contract_Storage : SmartContract.Framework.SmartContract
{
// There is no main here, it can be auto generation.
Expand Down
12 changes: 0 additions & 12 deletions tests/Template.NEP5.UnitTests/UnitTest_NEP5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ public void Test_totalSupply()
snapshot.Contracts.Add(hash, new Neo.Ledger.ContractState()
{
Manifest = new Neo.SmartContract.Manifest.ContractManifest()
{
Features = Neo.SmartContract.Manifest.ContractFeatures.HasStorage
}
});

snapshot.Storages.Add(new Neo.Ledger.StorageKey()
Expand Down Expand Up @@ -115,9 +112,6 @@ public void Test_totalSupply_empty()
snapshot.Contracts.Add(hash, new Neo.Ledger.ContractState()
{
Manifest = new Neo.SmartContract.Manifest.ContractManifest()
{
Features = Neo.SmartContract.Manifest.ContractFeatures.HasStorage
}
});

var result = engine.ExecuteTestCaseStandard("totalSupply");
Expand All @@ -139,9 +133,6 @@ public void Test_balanceOf()
snapshot.Contracts.Add(hash, new Neo.Ledger.ContractState()
{
Manifest = new Neo.SmartContract.Manifest.ContractManifest()
{
Features = Neo.SmartContract.Manifest.ContractFeatures.HasStorage
}
});

snapshot.Storages.Add(new Neo.Ledger.StorageKey()
Expand Down Expand Up @@ -174,9 +165,6 @@ public void Test_balanceOf_empty()
snapshot.Contracts.Add(hash, new Neo.Ledger.ContractState()
{
Manifest = new Neo.SmartContract.Manifest.ContractManifest()
{
Features = Neo.SmartContract.Manifest.ContractFeatures.HasStorage
}
});

var result = engine.ExecuteTestCaseStandard("balanceOf", address);
Expand Down