public async Task PostTransaction_InvalidNamespace() { TransactionValidator validator = CreateValidator(defaultAccounts); ByteString mutation = CreateMutation("http://wrong-root/"); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(mutation, new SignatureEvidence[0])); Assert.Equal("InvalidNamespace", exception.Reason); }
public async Task PostTransaction_InvalidMutation() { TransactionValidator validator = CreateValidator(new Dictionary <string, long>()); ByteString mutation = ByteString.Parse("aa"); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(mutation, new SignatureEvidence[0])); Assert.Equal("InvalidMutation", exception.Reason); }
public async Task PostTransaction_GenerateInvalidMutations() { Mutation generatedMutation = MessageSerializer.DeserializeMutation(CreateMutation(invalidNamespace)); TransactionValidator validator = CreateValidator(defaultAccounts, generatedMutation); ByteString mutation = CreateMutation(validNamespace); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(mutation, new SignatureEvidence[0])); Assert.Equal("InvalidNamespace", exception.Reason); Assert.Equal(null, store.AddedTransactions); }
public async Task Validate_InvalidSignature() { TransactionValidator validator = CreateValidator(defaultAccounts); ByteString mutation = CreateMutation("http://root/"); SignatureEvidence signature = new SignatureEvidence( ByteString.Parse("0013b0006543d4ab6e79f49559fbfb18e9d73596d63f39e2f12ebc2c9d51e2eb06"), ByteString.Parse("304402200c7fba6b623efd7e52731a11e6d7b99c2ae752c0f950b7a444ef7fb80162498c02202b01c74a4a04fb120860494de09bd6848f088927a7b07e3c3925b3894c8c89d4")); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(mutation, new[] { signature })); Assert.Equal("InvalidSignature", exception.Reason); }
public async Task PostTransaction_ValidationException() { TransactionValidator validator = new TransactionValidator( new TestStore(defaultAccounts, false), new TestValidator(true), "http://root/"); ByteString mutation = CreateMutation("http://root/"); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(mutation, new SignatureEvidence[0])); Assert.Equal("Test", exception.Reason); }
public async Task Validate_InvalidSignature() { TransactionValidator validator = CreateValidator(defaultAccounts); ByteString mutation = CreateMutation(validNamespace); SignatureEvidence signature = new SignatureEvidence( ByteString.Parse("0013b0006543d4ab6e79f49559fbfb18e9d73596d63f39e2f12ebc2c9d51e2eb06"), ByteString.Parse("3045022100e2ecc27c2e0d19329a0c7ad37e20fde00e64be235b2e7e86d285c18ff9c1e5b102200efa46125e057136f5008f4aa15a07e5ae4a0fcb2d00aa37862e246abbee74ab")); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(mutation, new[] { signature })); Assert.Equal("InvalidSignature", exception.Reason); }
public async Task PostTransaction_ConcurrencyException() { TransactionValidator validator = new TransactionValidator( new TestStore(defaultAccounts, true), new TestValidator(false), validNamespace); ByteString mutation = CreateMutation(validNamespace); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(mutation, new SignatureEvidence[0])); Assert.Equal("OptimisticConcurrency", exception.Reason); }
public async Task PostTransaction_EmptyMutation() { Dictionary <string, long> accounts = new Dictionary <string, long>(); TransactionValidator validator = CreateValidator(accounts); Mutation mutation = new Mutation( validNamespace, new Record[0], ByteString.Empty); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(new ByteString(MessageSerializer.SerializeMutation(mutation)), new SignatureEvidence[0])); Assert.Equal("InvalidMutation", exception.Reason); }
public async Task PostTransaction_ValidationException() { this.store = new TestStore(defaultAccounts, false); TransactionValidator validator = new TransactionValidator( this.store, new TestValidator(true), validNamespace); ByteString mutation = CreateMutation(validNamespace); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(mutation, new SignatureEvidence[0])); Assert.Equal("Test", exception.Reason); Assert.Equal(null, store.AddedTransactions); }
public async Task PostTransaction_UnbalancedTransaction() { Dictionary <string, long> accounts = new Dictionary <string, long>() { ["/account/1/"] = 100, ["/account/2/"] = 110, }; TransactionValidator validator = CreateValidator(accounts); ByteString mutation = CreateMutation("http://root/"); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(mutation, new SignatureEvidence[0])); Assert.Equal("UnbalancedTransaction", exception.Reason); }
public async Task Validate_DataMutationError() { PermissionBasedValidator validator = CreateValidator( new string[0], new Dictionary <string, PermissionSet>() { ["/"] = PermissionSet.Unset, ["/a/"] = new PermissionSet(Access.Permit, Access.Permit, Access.Permit, Access.Deny) }); ParsedMutation mutation = new ParsedMutation( new AccountStatus[0], new[] { new KeyValuePair <RecordKey, ByteString>(new RecordKey(RecordType.Data, LedgerPath.Parse("/a/"), "a"), ByteString.Parse("aabb")) }); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>(() => validator.Validate(mutation, new SignatureEvidence[0], new Dictionary <AccountKey, AccountStatus>())); Assert.Equal("CannotModifyData", exception.Reason); }
public async Task PostTransaction_MaxKeySize() { Dictionary <string, long> accounts = new Dictionary <string, long>(); TransactionValidator validator = CreateValidator(accounts); Mutation mutation = new Mutation( new ByteString(Encoding.UTF8.GetBytes("http://root/")), new Record[] { new Record( ByteString.Parse(new string('a', 1025 * 2)), new ByteString(BitConverter.GetBytes(100L).Reverse()), ByteString.Empty) }, ByteString.Empty); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(new ByteString(MessageSerializer.SerializeMutation(mutation)), new SignatureEvidence[0])); Assert.Equal("InvalidMutation", exception.Reason); }
public async Task PostTransaction_MaxKeySize() { Dictionary <string, long> accounts = new Dictionary <string, long>(); TransactionValidator validator = CreateValidator(accounts); Mutation mutation = new Mutation( validNamespace, new Record[] { new Record( new AccountKey(LedgerPath.Parse("/"), LedgerPath.Parse($"/{new string('a', 512)}/")).Key.ToBinary(), new ByteString(BitConverter.GetBytes(100L).Reverse()), ByteString.Empty) }, ByteString.Empty); TransactionInvalidException exception = await Assert.ThrowsAsync <TransactionInvalidException>( () => validator.PostTransaction(new ByteString(MessageSerializer.SerializeMutation(mutation)), new SignatureEvidence[0])); Assert.Equal("InvalidMutation", exception.Reason); Assert.Equal(null, store.AddedTransactions); }