public void ShouldDeployAContractWithConstructor()
 {
     using (var testrpcRunner = new TestRPCEmbeddedRunner())
     {
         try
         {
             testrpcRunner.RedirectOuputToDebugWindow = true;
             testrpcRunner.StartTestRPC();
             var web3        = new Web3();
             var addressFrom = (web3.Eth.Accounts.SendRequestAsync()).Result[0];
             // Deploy the contract and add the multiplier to the constructor
             var transactionHash =
                 MultiplicationService.DeployContractAsync(web3, addressFrom, new HexBigInteger(900000), 4).Result;
             Assert.IsNotNull(transactionHash);
             var receipt  = web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).Result;
             var contract = new MultiplicationService(web3, receipt.ContractAddress);
             // Do a multiplication
             var callResult = contract.MultiplyAsyncCall(4).Result;
             Assert.AreEqual(16, callResult);
         }
         finally
         {
             testrpcRunner.StopTestRPC();
         }
     }
 }
예제 #2
0
        public async void ShouldDeployAContractWithConstructor()
        {
            using (var testrpcRunner = new TestRPCEmbeddedRunner())
            {
                try
                {
                    testrpcRunner.RedirectOuputToDebugWindow = true;
                    testrpcRunner.StartTestRPC();

                    var web3        = new Web3.Web3();
                    var addressFrom = (await web3.Eth.Accounts.SendRequestAsync())[0];

                    var transactionService     = new TransactionReceiptPollingService(web3.TransactionManager);
                    var previousVersionAddress = "0x12890d2cce102216644c59dae5baed380d84830c";
                    var registrySevice         = await UportRegistryService.DeployContractAndGetServiceAsync(transactionService,
                                                                                                             web3,
                                                                                                             addressFrom,
                                                                                                             previousVersionAddress,
                                                                                                             new HexBigInteger(4712388));

                    Assert.Equal(previousVersionAddress, await registrySevice.PreviousPublishedVersionAsyncCall());
                }
                finally
                {
                    testrpcRunner.StopTestRPC();
                }
            }
        }
        public void ShouldDeploySmartIdentity()
        {
            using (var testrpcRunner = new TestRPCEmbeddedRunner())
            {
                try
                {
                    testrpcRunner.RedirectOuputToDebugWindow = true;
                    testrpcRunner.StartTestRPC();
                    var web3           = new Web3();
                    var addresses      = (web3.Eth.Accounts.SendRequestAsync()).Result;
                    var alice          = addresses[0];
                    var retailBank     = addresses[1];
                    var commercialBank = addresses[2];

                    var kycAttributeHash = "0xca02b2202ffaacbd499438ef6d594a48f7a7631b60405ec8f30a0d7c096dc3ff";
                    var endorsementHash  = "0xca02b2202ffaacbd499438ef6d594a48f7a7631b60405ec8f30a0d7c096d54d5";

                    //smartIdentity.GetOwnerAsync()

                    // Deploy the contract and add the multiplier to the constructor
                    var gas = web3.Eth.DeployContract.EstimateGasAsync(SmartIdentityService.ABI, SmartIdentityService.BYTE_CODE,
                                                                       alice).Result;
                    var transactionHash =
                        SmartIdentityService.DeployContractAsync(web3, alice, gas).Result;
                    Assert.IsNotNull(transactionHash);
                    var receipt = web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).Result;
                    Assert.IsNotNull(receipt);
                }
                finally
                {
                    testrpcRunner.StopTestRPC();
                }
            }
        }
예제 #4
0
        public static void StartTestRPC()
        {
            var testrpcRunner = new TestRPCEmbeddedRunner();

            testrpcRunner.RedirectOuputToDebugWindow = true;
            testrpcRunner.StartTestRPC();
            FeatureContext.Current.Add("testRpc", testrpcRunner);
        }
예제 #5
0
 public void LaunchTestRPC()
 {
     //We configure embeded test rpc instance
     Launcher = new TestRPCEmbeddedRunner();
     Launcher.RedirectOuputToDebugWindow = true;
     Launcher.Arguments = "--port 8545";
     //We configure embeded test rpc instance
     Launcher.StartTestRPC();
 }
예제 #6
0
        public async void Startup()
        {
            Rpc = new TestRPCEmbeddedRunner {
                RedirectOuputToDebugWindow = true
            };

            Rpc.StartTestRPC();
            Web3 = new Web3();

            Address = Web3.Eth.Accounts.SendRequestAsync().Result;
        }
예제 #7
0
        public static void Main(string[] args)
        {
            var launcher = new TestRPCEmbeddedRunner();

            launcher.RedirectOuputToDebugWindow = true;
            launcher.Arguments = "--port 8546";
            launcher.StartTestRPC();

            Console.ReadLine();
            launcher.StopTestRPC();
        }
        public void ShouldProperlyExecuteAllOrderedTests()
        {
            attributeHash1   = "0xca02b2202ffaacbd499438ef6d594a48f7a7631b60405ec8f30a0d7c096d54d5".ConvertToByteArray();
            attributeHash2   = "0xca02b2202ffaacbd499438ef6d594a48f7a7631b60405ec8f30a0d7c096dc3ff".ConvertToByteArray();
            attributeHash3   = "0xca02b2202ffaacbd499438ef6d594a48f7a7631b60405ec8f30a0d7c096c18ac".ConvertToByteArray();
            endorsementHash  = "0xca02b2202ffaacbd499438ef6d594a48f7a7631b60405ec8f30a0d7c096d54d5".ConvertToByteArray();
            endorsementHash2 = "0xca02b2202ffaacbd499438ef6d594a48f7a7631b60405ec8f30a0d7c096d59ab".ConvertToByteArray();

            rpc = new TestRPCEmbeddedRunner {
                RedirectOuputToDebugWindow = true
            };
            rpc.StartTestRPC();

            ShouldReadAndPopulate3Accounts();
            ShouldDeployContractForOwnerWithEnoughGasAndReturnReceipt();
            ShouldAddAnAttributeForOwner();

            rpc.Dispose();
        }
 public void ShouldDeploySmartIdentityMigrations()
 {
     using (var testrpcRunner = new TestRPCEmbeddedRunner())
     {
         try
         {
             testrpcRunner.RedirectOuputToDebugWindow = true;
             testrpcRunner.StartTestRPC();
             var web3        = new Web3();
             var addressFrom = (web3.Eth.Accounts.SendRequestAsync()).Result[0];
             // Deploy the contract and add the multiplier to the constructor
             var transactionHash =
                 MigrationsService.DeployContractAsync(web3, addressFrom, new HexBigInteger(900000)).Result;
             Assert.IsNotNull(transactionHash);
             var receipt = web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).Result;
             Assert.IsNotNull(receipt);
         }
         finally
         {
             testrpcRunner.StopTestRPC();
         }
     }
 }
예제 #10
0
        public async void ShouldRegisterVerification()
        {
            using (var testrpcRunner = new TestRPCEmbeddedRunner())
            {
                try
                {
                    testrpcRunner.RedirectOuputToDebugWindow = true;
                    testrpcRunner.StartTestRPC();

                    var web3        = new Web3.Web3();
                    var addressFrom = (await web3.Eth.Accounts.SendRequestAsync())[0];

                    var transactionService     = new TransactionReceiptPollingService(web3.TransactionManager);
                    var previousVersionAddress = "0x12890d2cce102216644c59dae5baed380d84830c";
                    var registrySevice         = await UportRegistryService.DeployContractAndGetServiceAsync(transactionService,
                                                                                                             web3,
                                                                                                             addressFrom,
                                                                                                             previousVersionAddress,
                                                                                                             new HexBigInteger(4712388));

                    var attestationId = "superAttestation";
                    var subject       = "0x22890d2cce102216644c59dae5baed380d84830c";
                    var value         = "true";

                    var txnReceipt = await registrySevice.SetAsyncAndGetReceipt(addressFrom, attestationId, subject,
                                                                                value, transactionService);

                    var storedValue = await registrySevice.GetAsyncCall(attestationId, addressFrom, subject);

                    Assert.Equal(value, storedValue);
                }
                finally
                {
                    testrpcRunner.StopTestRPC();
                }
            }
        }
예제 #11
0
        public async void ShouldDeployAContractWithConstructor()
        {
            using (var testrpcRunner = new TestRPCEmbeddedRunner())
            {
                try
                {
                    //The compiled solidity contract to be deployed

                    /*
                     * contract test {
                     *
                     * uint _multiplier;
                     *
                     * function test(uint multiplier){
                     *     _multiplier = multiplier;
                     * }
                     *
                     * function getMultiplier() constant returns(uint d){
                     *      return _multiplier;
                     * }
                     *
                     * function multiply(uint a) returns(uint d) { return a * _multiplier; }
                     *
                     * string public contractName = "Multiplier";
                     * }
                     */

                    var contractByteCode =
                        "0x6060604052604060405190810160405280600a81526020017f4d756c7469706c6965720000000000000000000000000000000000000000000081526020015060016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061008c57805160ff19168380011785556100bd565b828001600101855582156100bd579182015b828111156100bc57825182600050559160200191906001019061009e565b5b5090506100e891906100ca565b808211156100e457600081815060009055506001016100ca565b5090565b5050604051602080610303833981016040528080519060200190919050505b806000600050819055505b506101e2806101216000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806340490a901461004f57806375d0c0dc14610072578063c6888fa1146100ed5761004d565b005b61005c6004805050610119565b6040518082815260200191505060405180910390f35b61007f6004805050610141565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156100df5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610103600480803590602001909190505061012b565b6040518082815260200191505060405180910390f35b60006000600050549050610128565b90565b60006000600050548202905061013c565b919050565b60016000508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101da5780601f106101af576101008083540402835291602001916101da565b820191906000526020600020905b8154815290600101906020018083116101bd57829003601f168201915b50505050508156";

                    var abi =
                        @"[{""constant"":true,""inputs"":[],""name"":""getMultiplier"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":true,""inputs"":[],""name"":""contractName"",""outputs"":[{""name"":"""",""type"":""string""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""uint256""}],""type"":""constructor""}]";


                    testrpcRunner.RedirectOuputToDebugWindow = true;
                    testrpcRunner.StartTestRPC();


                    var web3        = new Web3();
                    var addressFrom = (await web3.Eth.Accounts.SendRequestAsync())[0];
                    //deploy the contract, including abi and a paramter of 7.
                    var transactionHash =
                        await
                        web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode, addressFrom,
                                                                 new HexBigInteger(900000), 7);

                    Assert.NotNull(transactionHash);

                    var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);

                    var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);

                    //get the function by name
                    var multiplyFunction = contract.GetFunction("multiply");

                    //do a function call (not transaction) and get the result
                    var callResult = await multiplyFunction.CallAsync <int>(69);

                    Assert.Equal(483, callResult);

                    var multiplierFunction = contract.GetFunction("getMultiplier");

                    var multiplier = await multiplierFunction.CallAsync <int>();

                    Assert.Equal(7, multiplier);

                    var contractNameFunction = contract.GetFunction("contractName");

                    var name = await contractNameFunction.CallAsync <string>();

                    Assert.Equal("Multiplier", name);
                }
                finally
                {
                    testrpcRunner.StopTestRPC();
                }
            }
        }