AccelerationTest.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Solana.Unity.Bolt.Test;
  2. using Solana.Unity.Rpc.Models;
  3. using Solana.Unity.Wallet;
  4. using Solana.Unity.Bolt;
  5. using Solana.Unity.Rpc;
  6. using System;
  7. using System.Threading.Tasks;
  8. using Solana.Unity.Wallet.Bip39;
  9. using World.Program;
  10. using System.Diagnostics;
  11. using Solana.Unity.Rpc.Types;
  12. namespace AccelerationTest {
  13. public class Test {
  14. public static async Task Run(Framework framework) {
  15. await Profiler.Run("AddAccelerationEntity", async () => {
  16. await AddAccelerationEntity(framework);
  17. });
  18. await Profiler.Run("InitializePositionComponentOnAccelerationEntity", async () => {
  19. await InitializePositionComponentOnAccelerationEntity(framework);
  20. });
  21. await Profiler.Run("DelegateComponent", async () => {
  22. await DelegateComponent(framework);
  23. });
  24. await Profiler.Run("ApplySimpleMovementSystemOnAccelerator 10", async () => {
  25. await ApplySimpleMovementSystemOnAccelerator(framework);
  26. });
  27. }
  28. public static async Task AddAccelerationEntity(Framework framework) {
  29. var addEntity = await Bolt.World.AddEntity(framework.Client, framework.WorldPda, framework.Wallet.Account.PublicKey, Commitment.Processed);
  30. framework.AccelerationEntityPda = addEntity.Pda;
  31. await framework.SendAndConfirmInstruction(addEntity.Instruction);
  32. }
  33. public static async Task InitializePositionComponentOnAccelerationEntity(Framework framework) {
  34. var initializeComponent = await Bolt.World.InitializeComponent(framework.Wallet.Account.PublicKey, framework.AccelerationEntityPda, framework.ExampleComponentPosition);
  35. framework.AccelerationComponentPositionPda = initializeComponent.Pda;
  36. await framework.SendAndConfirmInstruction(initializeComponent.Instruction);
  37. }
  38. public static async Task DelegateComponent(Framework framework) {
  39. var delegateComponent = await Bolt.World.DelegateComponent(framework.Wallet.Account.PublicKey, framework.AccelerationEntityPda, framework.ExampleComponentPosition);
  40. await framework.SendAndConfirmInstruction(delegateComponent.Instruction);
  41. }
  42. public static async Task ApplySimpleMovementSystemOnAccelerator(Framework framework) {
  43. for (int i = 0; i < 10; i++) {
  44. var apply = new ApplyAccounts() {
  45. Authority = framework.Wallet.Account.PublicKey,
  46. BoltSystem = framework.SystemSimpleMovement,
  47. World = framework.WorldPda,
  48. };
  49. var instruction = WorldProgram.Apply(apply, Bolt.World.SerializeArgs(new { direction = "Up" }));
  50. instruction.Keys.Add(AccountMeta.ReadOnly(framework.ExampleComponentPosition, false));
  51. instruction.Keys.Add(AccountMeta.Writable(framework.AccelerationComponentPositionPda, false));
  52. await framework.SendAndConfirmInstruction(framework.AcceleratorClient, instruction);
  53. await Task.Delay(50);
  54. }
  55. }
  56. }
  57. }