public void ContractPatcher_Test()
        {
            var code       = ReadContractCode(typeof(TokenContract));
            var updateCode = _patcher.Patch(code, false);

            code.ShouldNotBe(updateCode);
            var exception = Record.Exception(() => _auditor.Audit(updateCode, true));

            exception.ShouldBeNull();
        }
        public async Task Apply_ExecutionObserver_Test()
        {
            var contractCode = File.ReadAllBytes(typeof(TestContract).Assembly.Location);
            var code         = _patcher.Patch(contractCode, false);
            var assembly     = Assembly.Load(code);
            var executive    = new Executive(assembly)
            {
            };

            var hostSmartContractBridgeContext = _hostSmartContractBridgeContextService.Create();

            executive.SetHostSmartContractBridgeContext(_hostSmartContractBridgeContextService.Create());
            var transactionContext = CreateTransactionContext();

            await executive.ApplyAsync(transactionContext);

            hostSmartContractBridgeContext.TransactionContext.ShouldBeNull();
            transactionContext.Trace.ExecutionStatus.ShouldBe(ExecutionStatus.Executed);
            transactionContext.Trace.Error.ShouldBeNullOrEmpty();
            transactionContext.Trace.ReturnValue.ShouldBe((new Int32Output {
                Int32Value = -5
            }).ToByteString());
            transactionContext.Trace.StateSet.Reads.Count.ShouldBe(1);
            transactionContext.Trace.StateSet.Writes.Count.ShouldBe(1);
        }
示例#3
0
        private void PatchContractCode(string name)
        {
            var patchedCode = _contractPatcher.Patch(GetContactCode(name), true);
            var path        = Path.Combine(Environment.CurrentDirectory, name + ".dll.patched");

            File.WriteAllBytes(path, patchedCode);
        }