Пример #1
0
 public void TestSetup()
 {
     keyPair1      = new KeyPair(Wallet.GetPrivateKeyFromWIF("KyXwTh1hB76RRMquSvnxZrJzQx7h9nQP2PCRL38v6VDb5ip3nf1p"));
     sender        = Contract.CreateSignatureRedeemScript(keyPair1.PublicKey).ToScriptHash();
     rpcClientMock = UT_TransactionManager.MockRpcClient(sender, new byte[0]);
     nep17API      = new Nep17API(rpcClientMock.Object);
 }
Пример #2
0
        public void TestDeployContract()
        {
            byte[] script;
            var    manifest = new ContractManifest()
            {
                Permissions = new[] { ContractPermission.DefaultPermission },
                Abi         = new ContractAbi()
                {
                    Hash    = new byte[1].ToScriptHash(),
                    Events  = new ContractEventDescriptor[0],
                    Methods = new ContractMethodDescriptor[0]
                },
                Groups      = new ContractGroup[0],
                SafeMethods = WildcardContainer <string> .Create(),
                Trusts      = WildcardContainer <UInt160> .Create(),
                Extra       = null,
            };

            manifest.Features = ContractFeatures.HasStorage | ContractFeatures.Payable;
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall(ApplicationEngine.System_Contract_Create, new byte[1], manifest.ToString());
                script = sb.ToArray();
            }

            UT_TransactionManager.MockInvokeScript(rpcClientMock, script, new ContractParameter());

            ContractClient contractClient = new ContractClient(rpcClientMock.Object);
            var            result         = contractClient.CreateDeployContractTx(new byte[1], manifest, keyPair1);

            Assert.IsNotNull(result);
        }
Пример #3
0
        public async Task TestDeployContract()
        {
            byte[] script;
            var    manifest = new ContractManifest()
            {
                Permissions = new[] { ContractPermission.DefaultPermission },
                Abi         = new ContractAbi()
                {
                    Events  = new ContractEventDescriptor[0],
                    Methods = new ContractMethodDescriptor[0]
                },
                Groups             = new ContractGroup[0],
                Trusts             = WildcardContainer <ContractPermissionDescriptor> .Create(),
                SupportedStandards = new string[]
                {
                    "NEP-10"
                },
                Extra = null,
            };

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", new byte[1], manifest.ToJson().ToString());
                script = sb.ToArray();
            }

            UT_TransactionManager.MockInvokeScript(rpcClientMock, script, new ContractParameter());

            ContractClient contractClient = new ContractClient(rpcClientMock.Object);
            var            result         = await contractClient.CreateDeployContractTxAsync(new byte[1], manifest, keyPair1);

            Assert.IsNotNull(result);
        }
Пример #4
0
 public void TestSetup()
 {
     keyPair1      = new KeyPair(Wallet.GetPrivateKeyFromWIF("KyXwTh1hB76RRMquSvnxZrJzQx7h9nQP2PCRL38v6VDb5ip3nf1p"));
     sender        = Contract.CreateSignatureRedeemScript(keyPair1.PublicKey).ToScriptHash();
     multiSender   = Contract.CreateMultiSigContract(1, keyPair1.PublicKey).ScriptHash;
     address1      = Wallets.Helper.ToAddress(sender);
     rpcClientMock = UT_TransactionManager.MockRpcClient(sender, new byte[0]);
     walletAPI     = new WalletAPI(rpcClientMock.Object);
 }
Пример #5
0
        public async Task TestIsBlocked()
        {
            byte[] testScript = NativeContract.Policy.Hash.MakeScript("isBlocked", UInt160.Zero);
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.Boolean, Value = true
            });
            var result = await policyAPI.IsBlockedAsync(UInt160.Zero);

            Assert.AreEqual(true, result);
        }
Пример #6
0
        public async Task TestGetDecimals()
        {
            byte[] testScript = NativeContract.GAS.Hash.MakeScript("decimals");
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.Integer, Value = new BigInteger(NativeContract.GAS.Decimals)
            });

            var result = await nep17API.DecimalsAsync(NativeContract.GAS.Hash);

            Assert.AreEqual(NativeContract.GAS.Decimals, result);
        }
Пример #7
0
        public async Task TestGetSymbol()
        {
            byte[] testScript = NativeContract.GAS.Hash.MakeScript("symbol");
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.String, Value = NativeContract.GAS.Symbol
            });

            var result = await nep17API.SymbolAsync(NativeContract.GAS.Hash);

            Assert.AreEqual(NativeContract.GAS.Symbol, result);
        }
Пример #8
0
        public async Task TestGetMaxTransactionsPerBlock()
        {
            byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxTransactionsPerBlock", true);
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.Integer, Value = new BigInteger(512)
            });

            var result = await policyAPI.GetMaxTransactionsPerBlockAsync();

            Assert.AreEqual(512u, result);
        }
Пример #9
0
        public async Task TestGetFeePerByte()
        {
            byte[] testScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte");
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.Integer, Value = new BigInteger(1000)
            });

            var result = await policyAPI.GetFeePerByteAsync();

            Assert.AreEqual(1000L, result);
        }
Пример #10
0
        public void TestGetName()
        {
            byte[] testScript = NativeContract.GAS.Hash.MakeScript("name");
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.String, Value = NativeContract.GAS.Name
            });

            var result = nep5API.Name(NativeContract.GAS.Hash);

            Assert.AreEqual(NativeContract.GAS.Name, result);
        }
Пример #11
0
        public async Task TestBalanceOf()
        {
            byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", UInt160.Zero);
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.Integer, Value = new BigInteger(10000)
            });

            var balance = await nep17API.BalanceOfAsync(NativeContract.GAS.Hash, UInt160.Zero);

            Assert.AreEqual(10000, (int)balance);
        }
Пример #12
0
        public void TestGetMaxBlockSize()
        {
            byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxBlockSize");
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.Integer, Value = new BigInteger(1024u * 256u)
            });

            var result = policyAPI.GetMaxBlockSize();

            Assert.AreEqual(1024u * 256u, result);
        }
Пример #13
0
        public void TestInvoke()
        {
            byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", UInt160.Zero);
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.ByteArray, Value = "00e057eb481b".HexToBytes()
            });

            ContractClient contractClient = new ContractClient(rpcClientMock.Object);
            var            result         = contractClient.TestInvoke(NativeContract.GAS.Hash, "balanceOf", UInt160.Zero);

            Assert.AreEqual(30000000000000L, (long)result.Stack[0].ToStackItem().GetInteger());
        }
Пример #14
0
        public async Task TestGetBlockedAccounts()
        {
            byte[] testScript = NativeContract.Policy.Hash.MakeScript("getBlockedAccounts");
            UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
                Type = ContractParameterType.Array, Value = new[] { new ContractParameter {
                                                                        Type = ContractParameterType.Hash160, Value = UInt160.Zero
                                                                    } }
            });

            var result = await policyAPI.GetBlockedAccountsAsync();

            Assert.AreEqual(UInt160.Zero, result[0]);
        }
Пример #15
0
        public void TestDeployContract()
        {
            byte[] script;
            var    manifest = ContractManifest.CreateDefault(new byte[1].ToScriptHash());

            manifest.Features = ContractFeatures.HasStorage | ContractFeatures.Payable;
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall(InteropService.Contract.Create, new byte[1], manifest.ToString());
                script = sb.ToArray();
            }

            UT_TransactionManager.MockInvokeScript(rpcClientMock, script, new ContractParameter());

            ContractClient contractClient = new ContractClient(rpcClientMock.Object);
            var            result         = contractClient.CreateDeployContractTx(new byte[1], manifest, keyPair1);

            Assert.IsNotNull(result);
        }
Пример #16
0
 public void TestGetUnclaimedGas()
 {
     byte[] testScript = NativeContract.NEO.Hash.MakeScript("unclaimedGas", sender, 99);
     UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
         Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000)
     });
Пример #17
0
 public async Task TestGetTotalSupply()
 {
     byte[] testScript = NativeContract.GAS.Hash.MakeScript("totalSupply");
     UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter {
         Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000)
     });