New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for OP_EQUALVERIFY #317
Add tests for OP_EQUALVERIFY #317
Conversation
@@ -126,20 +133,41 @@ class OpCodeTests: XCTestCase { | |||
let dataOnTop: Data = context.stack.last! | |||
try opcode.execute(context) | |||
XCTAssertEqual(context.stack.count, stackCountAtFirst + 1, "\(opcode.name)(\(String(format: "%02x", opcode.value)) test: One data should be added to stack.") | |||
XCTAssertEqual(context.stack.dropLast().map(Data.init), stackSnapShot, "\(opcode.name)(\(String(format: "%02x", opcode.value)) test: The data except the top should be the same after the execution.") | |||
XCTAssertEqual(context.stack.dropLast().map({Data.init($0)}), stackSnapShot, "\(opcode.name)(\(String(format: "%02x", opcode.value)) test: The data except the top should be the same after the execution.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data($0)
is better.
Explicitly calling .init() should be avoided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I committed this line for my wrong.
But my Xcode shows this error.
Ambiguous use of 'init'
My environment is Xcode Version 10.0 beta 5 (10L221o)
What should I do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the same issue as here.
I think this is because you are using Xcode beta version.
https://bugs.swift.org/browse/SR-3842
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @akifuj said, you'd better write like this.
.map({Data($0)})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking link.
I fixed as .map { Data($0) }
try context.pushToStack(1) | ||
try context.pushToStack(3) | ||
XCTAssertEqual(context.stack.count, 2) | ||
XCTAssertThrowsError(try opcode.execute(context)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I fixed for the review. |
} catch OpCodeExecutionError.error("OP_VERIFY failed.") { | ||
// success | ||
} catch let error { | ||
fail(with: opcode, error: error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part should throw error like this.
"Should throw OpCodeExecutionError .error(\"OP_VERIFY failed.\"), but threw \(error)"
} catch OpCodeExecutionError.opcodeRequiresItemsOnStack(1) { | ||
// success | ||
} catch let error { | ||
fail(with: opcode, error: error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part should throw error like this.
"Should throw OpCodeExecutionError .error(\"OP_VERIFY failed.\"), but threw \(error)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change it.
@usatie Thanks for the review many times. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@GitCash send 1000 bits to @kzumu |
Hey kzumu, user usatie tipped you 1000 bits in Bitcoin Cash ( ~ $0.591 ). You can also add the "thumbs down" reaction to usatie's comment above to prevent future tips. |
close #279
I implemented tests for OP_EQUALVERIFY.
Would you review this?