public async Task DeployContract(Address address, ContractMetadataTemplate contractMetadataTemplate) { //For each chain, ChainFunctionMetadata should be used singlethreaded //which means transactions that deploy contracts need to execute serially //TODO: find a way to mark these transaction as a same group (maybe by using "r/w account sharing data"?) //TODO: need to //1.figure out where to have this "contractReferences" properly and //2.how to implement the action's that call other contracts and //3.as the contract reference can be changed, need to set up the contract update accordingly, which is the functions that are not yet implemented await chainFuncMetadata.DeployNewContract(address, contractMetadataTemplate); Logger.LogInformation( $"Metadata of contract {contractMetadataTemplate.FullName} are extracted successfully."); }
public async Task TestTryAddNewContract() { RunnerConfig.Instance.SdkDir = _mock.SdkDir; var runner = new SmartContractRunner(); var reg = new SmartContractRegistration { Category = 0, ContractBytes = ByteString.CopyFrom(_mock.ContractCode), ContractHash = Hash.FromRawBytes(_mock.ContractCode) }; var resC = runner.ExtractMetadata(typeof(TestContractC)); // Structure of the test data var groundTruthResC = new Dictionary <string, FunctionMetadataTemplate>( new[] // function metadata map for contract { new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func0", // local function name new FunctionMetadataTemplate( // local function metadata new HashSet <string>(), // calling set of this function metadata new HashSet <Resource>(new[] // local resource set of this function metadata { new Resource("${this}.resource4", DataAccessMode.AccountSpecific) // resource of the local resource set }))), new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func1", new FunctionMetadataTemplate( new HashSet <string>(), new HashSet <Resource>(new[] { new Resource("${this}.resource5", DataAccessMode.ReadOnlyAccountSharing) }))) }); var groundTruthTemplateC = new ContractMetadataTemplate(typeof(TestContractC).FullName, groundTruthResC, new Dictionary <string, Address>()); Assert.Equal(groundTruthTemplateC, resC, new ContractMetadataTemplateEqualityComparer()); var resB = runner.ExtractMetadata(typeof(TestContractB)); var groundTruthResB = new Dictionary <string, FunctionMetadataTemplate>(new[] { new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func0", new FunctionMetadataTemplate( new HashSet <string>(new[] { "${ContractC}.Func1" }), new HashSet <Resource>(new[] { new Resource("${this}.resource2", DataAccessMode.AccountSpecific) }))), new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func1", new FunctionMetadataTemplate( new HashSet <string>(), new HashSet <Resource>(new[] { new Resource("${this}.resource3", DataAccessMode.ReadOnlyAccountSharing) }))) }); var refB = new Dictionary <string, Address>(new [] { new KeyValuePair <string, Address>("ContractC", Address.FromRawBytes(ByteArrayHelpers.FromHexString("0x456745674567456745674567456745674567"))), }); var groundTruthTemplateB = new ContractMetadataTemplate(typeof(TestContractB).FullName, groundTruthResB, refB); Assert.Equal(groundTruthTemplateB, resB, new ContractMetadataTemplateEqualityComparer()); var resA = runner.ExtractMetadata(typeof(TestContractA)); var groundTruthResA = new Dictionary <string, FunctionMetadataTemplate>(new[] { new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func0(int)", new FunctionMetadataTemplate( new HashSet <string>(), new HashSet <Resource>())), new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func0", new FunctionMetadataTemplate( new HashSet <string>(new[] { "${this}.Func1" }), new HashSet <Resource>(new[] { new Resource("${this}.resource0", DataAccessMode.AccountSpecific) }))), new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func1", new FunctionMetadataTemplate( new HashSet <string>(new[] { "${this}.Func2" }), new HashSet <Resource>(new[] { new Resource("${this}.resource1", DataAccessMode.ReadOnlyAccountSharing) }))), new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func2", new FunctionMetadataTemplate( new HashSet <string>(), new HashSet <Resource>(new[] { new Resource("${this}.resource1", DataAccessMode.ReadOnlyAccountSharing), new Resource("${this}.resource2", DataAccessMode.ReadWriteAccountSharing) }))), new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func3", new FunctionMetadataTemplate( new HashSet <string>(new[] { "${_contractB}.Func0", "${this}.Func0", "${ContractC}.Func0" }), new HashSet <Resource>(new[] { new Resource("${this}.resource1", DataAccessMode.ReadOnlyAccountSharing) }))), new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func4", new FunctionMetadataTemplate( new HashSet <string>(new[] { "${this}.Func2", "${this}.Func2" }), new HashSet <Resource>())), new KeyValuePair <string, FunctionMetadataTemplate>( "${this}.Func5", new FunctionMetadataTemplate( new HashSet <string>(new[] { "${_contractB}.Func1", "${this}.Func3" }), new HashSet <Resource>())), }); var refA = new Dictionary <string, Address>(new [] { new KeyValuePair <string, Address>("ContractC", Address.FromRawBytes(ByteArrayHelpers.FromHexString("0x456745674567456745674567456745674567"))), new KeyValuePair <string, Address>("_contractB", Address.FromRawBytes(ByteArrayHelpers.FromHexString("0x123412341234123412341234123412341234"))), }); var groundTruthTemplateA = new ContractMetadataTemplate(typeof(TestContractA).FullName, groundTruthResA, refA); Assert.Equal(groundTruthTemplateA, resA, new ContractMetadataTemplateEqualityComparer()); //test fail cases await TestFailCases(runner); }
public async Task UpdateContract(Address address, ContractMetadataTemplate oldContractMetadataTemplate, ContractMetadataTemplate newContractMetadataTemplate) { await chainFuncMetadata.UpdateContract(address, oldContractMetadataTemplate, newContractMetadataTemplate); }