Skip to content

Commit

Permalink
#13 test read/generate signature request
Browse files Browse the repository at this point in the history
  • Loading branch information
noypi committed Apr 3, 2019
1 parent a88ff76 commit 2fde294
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
37 changes: 37 additions & 0 deletions IOST.Test/SignatureRequestTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;

namespace IOSTSdk.Test
{
[TestClass]
public class SignatureRequestTests
{
[TestInitialize]
public void Initialize()
{

}

[TestMethod]
public void TestReadGenerateSR()
{
var iost = new IOST(null);

var tx = iost.NewTransaction();

var pubk = "Gcv8c2tH8qZrUYnKdEEdTtASsxivic2834MQW6mgxqto";
tx.CreateAccount("newname", "creator", pubk, pubk);

var bb1 = tx.BytesForSigning();

string sig = tx.CreateSignatureRequest("some tag", Transaction.SRTRANSFERMETHOD_CLIENTCANTRANFER);

var readSig = Transaction.ReadSignatureRequest(sig);

CollectionAssert.AreEqual(bb1, Transaction.ToBytesForSigning(readSig.TransferDetails));

}
}
}
37 changes: 24 additions & 13 deletions IOST/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

public class Transaction
{
public Options Options { get; internal set; }
internal Rpcpb.TransactionRequest TransactionRequest { get; set; }
public static readonly string SRTRANSFERMETHOD_MUSTREPLY = SignatureRequest<Rpcpb.TransactionRequest>.TRANSFERMETHOD_MUSTREPLY;

public static readonly string SRTRANSFERMETHOD_CLIENTCANTRANFER = SignatureRequest<Rpcpb.TransactionRequest>.TRANSFERMETHOD_CLIENTCANTRANSFER;

internal Transaction(Options options)
{
Expand All @@ -26,6 +27,10 @@ internal Transaction(Options options)
};
}

public Options Options { get; internal set; }

internal Rpcpb.TransactionRequest TransactionRequest { get; set; }

public void AddAction(string contractID, string abi, params object[] args)
{
TransactionRequest.Actions.Add(NewAction(contractID, abi, IOST.JSONSerializer(args)));
Expand Down Expand Up @@ -122,17 +127,23 @@ public static byte[] SignatureToBytes(Rpcpb.Signature signature, Encoding encodi

public string CreateSignatureRequest(string tag, string transferMethod)
{
return ChainPay.CreateSignatureRequest<Rpcpb.TransactionRequest>(
new SignatureRequest<Rpcpb.TransactionRequest>()
{
BlockchainCode = "IOST",
BlockchainName = "Internet of Services Token",
MessageHash = Convert.ToBase64String(IOST.CryptoHashSha3_256(BytesForSigning())),
HashAlgo = "SHA3-256",
Tag = tag,
TransferDetails = TransactionRequest,
TransferMethod = transferMethod
});
var tx = new SignatureRequest<Rpcpb.TransactionRequest>()
{
BlockchainCode = "IOST",
BlockchainName = "Internet of Services Token",
MessageHash = Convert.ToBase64String(IOST.CryptoHashSha3_256(BytesForSigning())),
HashAlgo = "SHA3-256",
Tag = tag,
TransferDetails = TransactionRequest,
TransferMethod = transferMethod
};

return ChainPay.CreateSignatureRequest<Rpcpb.TransactionRequest>(tx);
}

public static SignatureRequest<Rpcpb.TransactionRequest> ReadSignatureRequest(string sig)
{
return ChainPay.ReadSignatureRequest<Rpcpb.TransactionRequest>(sig);
}

public static SignatureRequest<Rpcpb.TransactionRequest> ReadSignatureRequest(StreamReader reader)
Expand Down

0 comments on commit 2fde294

Please sign in to comment.