-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Optimized StorageMap * Remove 0s * Add unit test for storage access * Add comments * Changed unit test, for don't pass the prefix * Fix comment * Change to AsByteArray * Fix AsByteArray from byte * ToByteArray * Fix comment * Move and fix * Clean blank lines * Fix format * Fix format
- Loading branch information
Showing
11 changed files
with
451 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_StorageMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using Neo.SmartContract.Framework.Services.Neo; | ||
|
||
namespace Neo.Compiler.MSIL.TestClasses | ||
{ | ||
class Contract_StorageMap : SmartContract.Framework.SmartContract | ||
{ | ||
// There is no main here, it can be auto generation. | ||
|
||
#region Byte | ||
|
||
public static bool TestPutByte(byte[] key, byte[] value) | ||
{ | ||
var storage = Storage.CurrentContext.CreateMap(0xAA); | ||
storage.Put(key, value); | ||
return true; | ||
} | ||
|
||
public static bool TestDeleteByte(byte[] key) | ||
{ | ||
var storage = Storage.CurrentContext.CreateMap(0xAA); | ||
var value = storage.Get(key); | ||
var exists = value.Length > 0; | ||
storage.Delete(key); | ||
return exists; | ||
} | ||
|
||
public static byte[] TestGetByte(byte[] key) | ||
{ | ||
var storage = Storage.CurrentContext.CreateMap(0xAA); | ||
var value = storage.Get(key); | ||
return value; | ||
} | ||
|
||
#endregion | ||
|
||
#region String | ||
|
||
public static bool TestPutString(byte[] key, byte[] value) | ||
{ | ||
var prefix = "aa"; | ||
var storage = Storage.CurrentContext.CreateMap(prefix); | ||
storage.Put(key, value); | ||
return true; | ||
} | ||
|
||
public static bool TestDeleteString(byte[] key) | ||
{ | ||
var prefix = "aa"; | ||
var storage = Storage.CurrentContext.CreateMap(prefix); | ||
var value = storage.Get(key); | ||
var exists = value.Length > 0; | ||
storage.Delete(key); | ||
return exists; | ||
} | ||
|
||
public static byte[] TestGetString(byte[] key) | ||
{ | ||
var prefix = "aa"; | ||
var storage = Storage.CurrentContext.CreateMap(prefix); | ||
var value = storage.Get(key); | ||
return value; | ||
} | ||
|
||
#endregion | ||
|
||
#region ByteArray | ||
|
||
public static bool TestPutByteArray(byte[] key, byte[] value) | ||
{ | ||
var prefix = new byte[] { 0x00, 0xFF }; | ||
var storage = Storage.CurrentContext.CreateMap(prefix); | ||
storage.Put(key, value); | ||
return true; | ||
} | ||
|
||
public static bool TestDeleteByteArray(byte[] key) | ||
{ | ||
var prefix = new byte[] { 0x00, 0xFF }; | ||
var storage = Storage.CurrentContext.CreateMap(prefix); | ||
var value = storage.Get(key); | ||
var exists = value.Length > 0; | ||
storage.Delete(key); | ||
return exists; | ||
} | ||
|
||
public static byte[] TestGetByteArray(byte[] key) | ||
{ | ||
var prefix = new byte[] { 0x00, 0xFF }; | ||
var storage = Storage.CurrentContext.CreateMap(prefix); | ||
var value = storage.Get(key); | ||
return value; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.