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

Validate manifest after compilation #658

Merged
merged 16 commits into from
Nov 12, 2021

Conversation

shargon
Copy link
Member

@shargon shargon commented Jun 25, 2021

Close #657

@superboyiii
Copy link
Member

superboyiii commented Jul 19, 2021

Close #657

Should update to Neo v3.0.0-CI01295. Dependency is too old.

@superboyiii
Copy link
Member

superboyiii commented Jul 19, 2021

Test Fail
I tried several kinds of duplicated dispaly name, but none of them throw exception.

        [DisplayName("Notify")]
        public static event Action<string, object, object> Notify;

        [DisplayName("Notify")]
        public static event Action<BigInteger> Notice;

        [DisplayName("Notify")]
        public static event Action<BigInteger> AA;

nccs compile:

E:\PR-test\devpack-PR#658\neo-devpack-dotnet\pnUSDT>nccs pnUSDT.csproj
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
Created E:\PR-test\devpack-PR#658\neo-devpack-dotnet\pnUSDT\bin\sc\pnUSDT.nef
Created E:\PR-test\devpack-PR#658\neo-devpack-dotnet\pnUSDT\bin\sc\pnUSDT.manifest.json
Compilation completed successfully.

manifest:

image

@shargon
Copy link
Member Author

shargon commented Jul 19, 2021

@superboyiii If I change the UT for your example, it throw an exception :S

image

@shargon
Copy link
Member Author

shargon commented Oct 19, 2021

@superboyiii could you check it again?

@shargon
Copy link
Member Author

shargon commented Oct 31, 2021

Ping @superboyiii

@superboyiii
Copy link
Member

I'll test again.

@superboyiii
Copy link
Member

superboyiii commented Nov 3, 2021

@shargon Still Failed

using Neo;
using Neo.SmartContract;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;
using System;
using System.ComponentModel;
using System.Numerics;

namespace TestNetFee
{
    [ContractPermission("0x42e54382e86dcdca09e0da8bb67e2fac4d498744", "test")]
    [SupportedStandards("NEP-17")]
    [ManifestExtra("Author", "Neo")]
    [ManifestExtra("Email", "dev@neo.org")]
    [ManifestExtra("Description", "This is a contract example")]
    [ContractSourceCode("https://github.com/neo-project/neo")]
    public class TestSimple : SmartContract
    {
        [DisplayName("Unlock")]
        public static event Action<UInt160, UInt160, BigInteger> UnlockEvent;
        [DisplayName("Unlock")]
        public static event Action<object> IsPausedEvent;
        //TODO: Replace it with your own address.
        [InitialValue("NdUL5oDPD159KeFpD5A9zw5xNF1xLX6nLT", ContractParameterType.Hash160)]
        static readonly UInt160 Owner = default;

        [InitialValue("42e54382e86dcdca09e0da8bb67e2fac4d498744", ContractParameterType.ByteArray)]// little endian
        private static readonly byte[] ProxyScriptHash = default;

        private static bool IsOwner() => Runtime.CheckWitness(Owner);

        public static bool Unlock(UInt160 toAssetHash, UInt160 toAddress, BigInteger amount)
        {
            if (!IsOwner()) throw new Exception("No authorization.");
            var Params = new object[] { Runtime.ExecutingScriptHash, toAddress, amount, null };
            // transfer asset from proxy contract to toAddress
            Contract.Call(toAssetHash, "transfer", CallFlags.All, Params);
            UnlockEvent(toAssetHash, toAddress, amount);
            return true;
        }

        public static bool IsPaused()
        {
            var Params = new object[] { };
            // transfer asset from proxy contract to toAddress
            bool isPaused = (bool)Contract.Call((UInt160)ProxyScriptHash, "isPaused", CallFlags.All, Params);
            IsPausedEvent(isPaused);
            return isPaused;
        }

        public static void _deploy(object data, bool update)
        {
            if (update) return;

            // It will be executed during deploy
            Storage.Put(Storage.CurrentContext, "Hello", "World");
        }

        public static void Update(ByteString nefFile, string manifest)
        {
            if (!IsOwner()) throw new Exception("No authorization.");
            ContractManagement.Update(nefFile, manifest, null);
        }

        public static void Destroy()
        {
            if (!IsOwner()) throw new Exception("No authorization.");
            ContractManagement.Destroy();
        }

    }
}

You could try it on local. Obviously there're two Unlock in manifest and compiler doesn't throw any exception.

1>------ Rebuild All started: Project: Neo.SmartContract.Framework, Configuration: Debug Any CPU ------
Restored E:\PR-test\neo-PR#657\neo-devpack-dotnet\tests\Neo.SmartContract.Framework.UnitTests\Neo.SmartContract.Framework.UnitTests.csproj (in 213 ms).
1>Neo.SmartContract.Framework -> E:\PR-test\neo-PR#657\neo-devpack-dotnet\src\Neo.SmartContract.Framework\bin\Debug\net5.0\Neo.SmartContract.Framework.dll
2>------ Rebuild All started: Project: TestSimple, Configuration: Debug Any CPU ------
2>TestSimple -> E:\PR-test\neo-PR#657\neo-devpack-dotnet\TestSimple\bin\Debug\net5.0\TestSimple.dll
2>Start NeoContract converter, Source File: E:\PR-test\neo-PR#657\neo-devpack-dotnet\TestSimple\bin\Debug\net5.0\TestSimple.dll
2>  Determining projects to restore...
2>  All projects are up-to-date for restore.
2>  Determining projects to restore...
2>  All projects are up-to-date for restore.
2>Created E:\PR-test\neo-PR#657\neo-devpack-dotnet\TestSimple\bin\sc\TestSimple.nef
2>Created E:\PR-test\neo-PR#657\neo-devpack-dotnet\TestSimple\bin\sc\TestSimple.manifest.json
2>Compilation completed successfully.

But it's checked when deployed by neo-cli.

1635919275(1)

@shargon
Copy link
Member Author

shargon commented Nov 3, 2021

@superboyiii Thanks for your feedback, please try it again :)

@superboyiii
Copy link
Member

It works now. @shargon

E:\PR-test\devpack-PR#658\neo-devpack-dotnet\pnUSDT>nccs TestNetFee.cs
error NC3003: The generated Abi it's not valid.
Compilation failed.

superboyiii
superboyiii previously approved these changes Nov 10, 2021
erikzhang
erikzhang previously approved these changes Nov 11, 2021
Comment on lines +462 to +463
if (methodsExported.Any(u => u.Name == method.Name && u.Parameters.Length == method.Parameters.Length))
throw new CompilationException(symbol, DiagnosticId.MethodNameConflict, $"Duplicate method key: {method.Name},{method.Parameters.Length}.");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shargon shargon merged commit 697c4a2 into neo-project:master Nov 12, 2021
@shargon shargon deleted the validate-manifest branch November 12, 2021 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nccs compiles contract that won't deploy
3 participants