Skip to content

Commit b7c38c2

Browse files
committed
Allow sender balance to equal the amount sent in the token contract
Thanks Steve!
1 parent 911bd15 commit b7c38c2

File tree

7 files changed

+6
-19
lines changed

7 files changed

+6
-19
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
33
"base_api",
4+
"user_contracts",
45
"human_readable_name_registry",
56
"base_token",
67
"leader_election"

base_token/dist/base_token.wasm

-131 Bytes
Binary file not shown.

base_token/src/base_token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn transfer(receiver_address: Vec<u8>, amount: u64) -> Result<(), Error> {
2222
let sender_balance = read_int(sender());
2323
let receiver_balance = read_int(receiver_address.clone());
2424

25-
if sender_balance > amount {
25+
if sender_balance => amount {
2626
write_int(sender(), sender_balance - amount);
2727
write_int(receiver_address, receiver_balance + amount);
2828
Ok(())

base_token/src/lib.rs

-16
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ extern crate wee_alloc;
2121
#[cfg(not(test))]
2222
#[global_allocator]
2323
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
24-
#[cfg(not(test))]
25-
use core::panic::PanicInfo;
26-
27-
#[cfg(not(test))]
28-
#[panic_implementation]
29-
fn panic(_info: &PanicInfo) -> ! {
30-
loop {}
31-
}
32-
33-
#[cfg(not(test))]
34-
#[alloc_error_handler]
35-
fn out_of_memory(_: ::core::alloc::Layout) -> ! {
36-
loop {}
37-
}
38-
39-
4024
mod error;
4125

4226
#[cfg(not(test))]

base_token/test/support/fake-blockchain.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const WasmRPC = require('/Users/masonf/src/simple-wasm').default;
1+
const WasmRPC = require('/Users/masonf/src/js-wasm-rpc-client').default;
22
const { execFileSync } = require('child_process');
33
const cbor = require('cbor');
44
const { StringDecoder } = require('string_decoder');
@@ -14,6 +14,7 @@ class FakeBlockchain extends WasmRPC {
1414
_read: (keyPtr) => {
1515
var key = this.readPointer(keyPtr);
1616
if(this.storage[key]) {
17+
// console.log(`${key} -> ${this.storage[key]}`)
1718
return this.writePointer(this.storage[key]);
1819
} else {
1920
return this.writePointer(new Uint8Array([]));
@@ -23,6 +24,7 @@ class FakeBlockchain extends WasmRPC {
2324
var key = this.readPointer(keyPtr);
2425
var value = this.readPointer(valuePtr);
2526

27+
// console.log(`${key} = ${value}`)
2628
this.storage[key] = value;
2729
},
2830
throw: console.log,

base_token/test/token-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('BaseToken', function() {
1717
defaultSender: SENDER,
1818
});
1919

20-
await blockchain.loadFile("../target/wasm32-unknown-unknown/release/base_token.wasm");
20+
await blockchain.loadFile("dist/base_token.wasm");
2121
});
2222

2323
afterEach(() => blockchain.reset());
-86 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)