public void SmartContractList_CanAccessValueUsingIndexTest() { var listName = "testList"; var source = new MemoryDictionarySource(); var root = new ContractStateRoot(source); IContractState state = root.StartTracking(); IPersistenceStrategy persistenceStrategy = new PersistenceStrategy(state); var persistentState = new PersistentState( persistenceStrategy, this.contractPrimitiveSerializer, uint160.One); var list = new SmartContractList <string>(persistentState, listName); Assert.Equal((uint)0, list.Count); // Set a value in the list list.Add("Test"); list.Add("Test2"); var testItem = list.GetValue(0); var testItem2 = list.GetValue(1); var firstItemHash = $"{listName}[0]"; var secondItemHash = $"{listName}[1]"; var item = persistentState.GetString(firstItemHash); var item2 = persistentState.GetString(secondItemHash); Assert.Equal(testItem, item); Assert.Equal(testItem2, item2); }
public CreateWithAllParameters(ISmartContractState state, char aChar, Address anAddress, bool aBool, int anInt, long aLong, uint aUint, ulong aUlong, UInt128 aUInt128, UInt256 aUInt256, string aString, byte[] bytes) : base(state) { PersistentState.SetChar("char", aChar); PersistentState.SetAddress("Address", anAddress); PersistentState.SetBool("bool", aBool); PersistentState.SetInt32("int", anInt); PersistentState.SetInt64("long", aLong); PersistentState.SetUInt32("uint", aUint); PersistentState.SetUInt64("ulong", aUlong); PersistentState.SetUInt128("UInt128", aUInt128); PersistentState.SetUInt256("UInt256", aUInt256); PersistentState.SetString("string", aString); PersistentState.SetBytes("bytes", bytes); this.Log(new Log { Char = aChar, Address = anAddress, Bool = aBool, Int = anInt, Long = aLong, Uint = aUint, Ulong = aUlong, UInt128 = aUInt128, UInt256 = aUInt256, String = aString, Bytes = bytes }); Assert(PersistentState.GetChar("char") == aChar); Assert(PersistentState.GetAddress("Address") == anAddress); Assert(PersistentState.GetBool("bool") == aBool); Assert(PersistentState.GetInt32("int") == anInt); Assert(PersistentState.GetInt64("long") == aLong); Assert(PersistentState.GetUInt128("UInt128") == aUInt128); Assert(PersistentState.GetUInt256("UInt256") == aUInt256); Assert(PersistentState.GetString("string") == aString); byte[] bytesStored = PersistentState.GetBytes("bytes"); Assert(bytesStored.Length == bytes.Length); for (int i = 0; i < bytes.Length; i++) { Assert(bytesStored[i] == bytes[i]); } }
private string GetTicket(string ticketUniqueId) { return(PersistentState.GetString($"Ticket:{ticketUniqueId}")); }
private string GetEventTier(string eventTierUniqueId) { return(PersistentState.GetString($"EventTier:{eventTierUniqueId}")); }
private string GetCustomer(Address address) { return(PersistentState.GetString($"Customer:{address}")); }
private string GetHost(Address address) { return(PersistentState.GetString($"Host:{address}")); }