diff --git a/src/Week4/Bank.sol b/src/Week4/Bank.sol index c17bcf1..7c3f51d 100644 --- a/src/Week4/Bank.sol +++ b/src/Week4/Bank.sol @@ -18,15 +18,17 @@ contract Bank { } else { Node memory n = nodes[head]; - if (n.value < msg.value) { - nodes[msg.sender] = Node(head, msg.value, msg.sender); + uint256 amountValue = nodes[msg.sender].value + msg.value; + + if (n.value < amountValue) { + nodes[msg.sender] = Node(head, amountValue, msg.sender); head = msg.sender; return; } while (n.next != address(0)) { - if (msg.value > nodes[n.next].value) { - nodes[msg.sender] = Node(n.next, msg.value, msg.sender); + if (amountValue > nodes[n.next].value) { + nodes[msg.sender] = Node(n.next, amountValue, msg.sender); nodes[n.depositer].next = msg.sender; return; } @@ -34,7 +36,7 @@ contract Bank { } if (n.next == address(0)) { - nodes[msg.sender] = Node(address(0), msg.value, msg.sender); + nodes[msg.sender] = Node(address(0), amountValue, msg.sender); nodes[n.depositer].next = msg.sender; return; } diff --git a/test/Bank.t.sol b/test/Bank.t.sol index c690280..3e231a7 100644 --- a/test/Bank.t.sol +++ b/test/Bank.t.sol @@ -42,7 +42,8 @@ contract BankTest is Test { _deposit(kate, 111); // _deposit(linda, 12); // _deposit(minnie, 13); - _deposit(nancy, 14); + _deposit(nancy, 13); + _deposit(dave, 10); bank.nodes(bank.head()); // assertEq(deposit, charlie); @@ -52,7 +53,7 @@ contract BankTest is Test { (address next1, uint256 value1, address deposit1) = bank.nodes(jessie); // assertEq(deposit, 15); - assertEq(next1, nancy); + assertEq(next1, dave); assertEq(value1, 15); }