public IEnumerator TxAlreadyExistsInCacheRecoverTest() { return(AsyncEditorTestUtility.AsyncTest(async() => { byte[] privateKey = CryptoUtils.GeneratePrivateKey(); byte[] publicKey = CryptoUtils.PublicKeyFromPrivateKey(privateKey); int callCounter = 0; EvmContract invalidNonceContract = await ContractTestUtility.GetEvmContract( privateKey, publicKey, this.testContext.TestsAbi, (client, _, __) => { ControllableNonceTxMiddleware controllableNonceTxMiddleware = new ControllableNonceTxMiddleware(publicKey, client); controllableNonceTxMiddleware.GetNextNonceAsyncCalled += nextNonce => { switch (callCounter) { case 0: Assert.AreEqual(1, nextNonce); controllableNonceTxMiddleware.ForcedNextNonce = 1; break; case 1: Assert.AreEqual(1, nextNonce); controllableNonceTxMiddleware.ForcedNextNonce = null; break; case 2: Assert.AreEqual(2, nextNonce); break; default: Assert.Fail($"Unexpected call #{callCounter}"); break; } callCounter++; }; return new ITxMiddlewareHandler[] { controllableNonceTxMiddleware, new SignedTxMiddleware(privateKey) }; }); await invalidNonceContract.CallAsync("setTestUint", new BigInteger(123456789)); await invalidNonceContract.CallAsync("setTestUint", new BigInteger(123456789)); }, timeout: 20000)); }
public IEnumerator SpeculativeNextNonceTest() { return(AsyncEditorTestUtility.AsyncTest(async() => { byte[] privateKey = CryptoUtils.GeneratePrivateKey(); byte[] publicKey = CryptoUtils.PublicKeyFromPrivateKey(privateKey); int callCounter = 0; EvmContract invalidNonceContract = await ContractTestUtility.GetEvmContract( privateKey, publicKey, this.testContext.TestsAbi, (client, _, __) => { ControllableNonceTxMiddleware controllableNonceTxMiddleware = new ControllableNonceTxMiddleware(publicKey, client); controllableNonceTxMiddleware.GetNextNonceAsyncCalled += nextNonce => { switch (callCounter) { case 0: Assert.AreEqual(1, nextNonce); controllableNonceTxMiddleware.FailOnGetNonceFromNode = true; break; case 1: Assert.AreEqual(2, nextNonce); break; case 2: Assert.AreEqual(3, nextNonce); controllableNonceTxMiddleware.FailOnGetNonceFromNode = false; controllableNonceTxMiddleware.ForcedNextNonce = UInt64.MaxValue; break; case 3: Assert.AreEqual(UInt64.MaxValue, nextNonce); break; case 4: Assert.AreEqual(UInt64.MaxValue, nextNonce); break; case 5: Assert.AreEqual(UInt64.MaxValue, nextNonce); controllableNonceTxMiddleware.ForcedNextNonce = null; break; case 6: Assert.AreEqual(4, nextNonce); break; case 7: Assert.AreEqual(5, nextNonce); break; default: Assert.Fail($"Unexpected call #{callCounter}"); break; } callCounter++; }; return new ITxMiddlewareHandler[] { controllableNonceTxMiddleware, new SignedTxMiddleware(privateKey) }; }); try { await invalidNonceContract.CallAsync("setTestUint", new BigInteger(123456789)); await invalidNonceContract.CallAsync("setTestUint", new BigInteger(123456789)); await invalidNonceContract.CallAsync("setTestUint", new BigInteger(123456789)); await invalidNonceContract.CallAsync("setTestUint", new BigInteger(123456789)); await invalidNonceContract.CallAsync("setTestUint", new BigInteger(123456789)); Assert.AreEqual(8, callCounter); } catch (InvalidTxNonceException e) { Assert.Catch <InvalidTxNonceException>(() => { throw e; }); } }, timeout: 20000)); }