浏览代码

:recycle: TS&C# Unified Buffer & Component delegation instruction

Danilo Guanabara 1 月之前
父节点
当前提交
bf0cf12070

+ 1 - 2
clients/csharp/Solana.Unity.Bolt.Test/AccelerationTest.cs

@@ -43,8 +43,7 @@ namespace AccelerationTest {
 
         public static async Task DelegateComponent(Framework framework) {
             var delegateComponent = await Bolt.World.DelegateComponent(framework.Wallet.Account.PublicKey, framework.AccelerationEntityPda, framework.ExampleComponentPosition);
-            await framework.SendAndConfirmInstruction(delegateComponent.gTransaction);
-            var delegateBuffer = await Bolt.World.DelegateBuffer();
+            await framework.SendAndConfirmInstruction(delegateComponent.Instruction);
         }
 
         public static async Task ApplySimpleMovementSystemOnAccelerator(Framework framework) {

+ 24 - 13
clients/csharp/Solana.Unity.Bolt/WorldProgram/Bolt/DelegateComponent.cs

@@ -20,12 +20,18 @@ namespace Bolt {
         }
 
         public static async Task<DelegateComponentInstruction> DelegateComponent(PublicKey payer, PublicKey entity, PublicKey componentId, string seed = "") {
-            var account = WorldProgram.FindComponentPda(componentId, entity, seed);
-            var bufferPda = WorldProgram.FindBufferPda(account, componentId);
-            var delegationRecord = WorldProgram.FindDelegationProgramPda("delegation", account);
-            var delegationMetadata = WorldProgram.FindDelegationProgramPda("delegation-metadata", account);
+            var componentPda = WorldProgram.FindComponentPda(componentId, entity, seed);
+            var componentBuffer = WorldProgram.FindBufferPda(componentPda);
 
-            byte[] discriminator = new byte[] { 90, 147, 75, 178, 85, 88, 4, 137 };
+            var componentDelegationRecord = WorldProgram.FindDelegationProgramPda("delegation", componentPda);
+            var componentDelegationMetadata = WorldProgram.FindDelegationProgramPda("delegation-metadata", componentPda);
+
+            var worldProgram = new PublicKey(WorldProgram.ID);
+            var bufferDelegationRecord = WorldProgram.FindDelegationProgramPda("delegation", componentBuffer);
+            var bufferDelegationMetadata = WorldProgram.FindDelegationProgramPda("delegation-metadata", componentBuffer);
+            var bufferBuffer = WorldProgram.FindBufferPda(componentBuffer, worldProgram);
+
+            byte[] discriminator = new byte[] { 191, 212, 179, 193, 178, 94, 119, 93 };
             uint commitFrequencyMs = 0;
             byte[] commitFrequencyBytes = BitConverter.GetBytes(commitFrequencyMs);
             if (!BitConverter.IsLittleEndian) Array.Reverse(commitFrequencyBytes);
@@ -38,22 +44,27 @@ namespace Bolt {
             Array.Copy(validator, 0, data, discriminator.Length + commitFrequencyBytes.Length, validator.Length);
 
             TransactionInstruction instruction = new TransactionInstruction() {
-                ProgramId = componentId,
+                ProgramId = new PublicKey(WorldProgram.ID),
                 Keys = new List<AccountMeta>() {
-                    AccountMeta.ReadOnly(payer, true),
-                    AccountMeta.ReadOnly(entity, false),
-                    AccountMeta.Writable(account, false),
+                    AccountMeta.Writable(payer, true),
+                    AccountMeta.Writable(componentPda, false),
+                    AccountMeta.Writable(componentBuffer, false),
                     AccountMeta.ReadOnly(componentId, false),
-                    AccountMeta.Writable(bufferPda, false),
-                    AccountMeta.Writable(delegationRecord, false),
-                    AccountMeta.Writable(delegationMetadata, false),
+                    AccountMeta.Writable(WorldProgram.FindBufferPda(componentPda, componentId), false),
+                    AccountMeta.Writable(componentDelegationRecord, false),
+                    AccountMeta.Writable(componentDelegationMetadata, false),
                     AccountMeta.ReadOnly(WorldProgram.DelegationProgram, false),
                     AccountMeta.ReadOnly(SystemProgram.ProgramIdKey, false),
+                    AccountMeta.ReadOnly(entity, false),
+                    AccountMeta.ReadOnly(worldProgram, false),
+                    AccountMeta.Writable(bufferBuffer, false),
+                    AccountMeta.Writable(bufferDelegationRecord, false),
+                    AccountMeta.Writable(bufferDelegationMetadata, false),
                 },
                 Data = data,
             };
             return new DelegateComponentInstruction() {
-                Pda = WorldProgram.FindDelegationProgramPda(seed, entity),
+                Pda = componentPda,
                 Instruction = instruction,
             };
         }

+ 3 - 3
tests/script.sh

@@ -8,8 +8,8 @@ sleep 5
 echo "Running TypeScript tests..."
 yarn run ts-mocha -p ./tsconfig.json -t 1000000 clients/typescript/test/main.ts
 
-# echo "Running C# tests..."
-# cd clients/csharp/Solana.Unity.Bolt.Test
-# dotnet run --configuration Release
+echo "Running C# tests..."
+cd clients/csharp/Solana.Unity.Bolt.Test
+dotnet run --configuration Release
 
 echo "Tests completed."